This will provide you with a nice little tea maker, which will dip your teabag in and take it out after a specified amount of time. You can set how long to brew for and whether you want your teabag dipped, too.
Dependencies: TextLCD mbed Servo
main.cpp@0:dcc453868f80, 2011-06-24 (annotated)
- Committer:
- Eggotape
- Date:
- Fri Jun 24 12:47:35 2011 +0000
- Revision:
- 0:dcc453868f80
Could add a temperature sensor to see if the tea is going cold, and text alerts to remind you to pick up your mug
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Eggotape | 0:dcc453868f80 | 1 | #include "mbed.h" |
Eggotape | 0:dcc453868f80 | 2 | #include "Servo.h" |
Eggotape | 0:dcc453868f80 | 3 | #include "TextLCD.h" |
Eggotape | 0:dcc453868f80 | 4 | |
Eggotape | 0:dcc453868f80 | 5 | TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7 |
Eggotape | 0:dcc453868f80 | 6 | DigitalIn setbutton(p5); |
Eggotape | 0:dcc453868f80 | 7 | DigitalIn gobutton(p6); |
Eggotape | 0:dcc453868f80 | 8 | Servo myservo(p21); |
Eggotape | 0:dcc453868f80 | 9 | Timer t; |
Eggotape | 0:dcc453868f80 | 10 | |
Eggotape | 0:dcc453868f80 | 11 | int set(); |
Eggotape | 0:dcc453868f80 | 12 | int dip(); |
Eggotape | 0:dcc453868f80 | 13 | int set (int currentstate); |
Eggotape | 0:dcc453868f80 | 14 | int displaystate(int currentstate); |
Eggotape | 0:dcc453868f80 | 15 | int maketea(int currentstate); |
Eggotape | 0:dcc453868f80 | 16 | int dipping(); |
Eggotape | 0:dcc453868f80 | 17 | |
Eggotape | 0:dcc453868f80 | 18 | int main() { |
Eggotape | 0:dcc453868f80 | 19 | int state; |
Eggotape | 0:dcc453868f80 | 20 | state = 1; |
Eggotape | 0:dcc453868f80 | 21 | myservo = 1; |
Eggotape | 0:dcc453868f80 | 22 | lcd.cls(); |
Eggotape | 0:dcc453868f80 | 23 | lcd.printf("Start?\n"); |
Eggotape | 0:dcc453868f80 | 24 | while(1) { |
Eggotape | 0:dcc453868f80 | 25 | if (setbutton == 1) { |
Eggotape | 0:dcc453868f80 | 26 | state = set(state); |
Eggotape | 0:dcc453868f80 | 27 | } |
Eggotape | 0:dcc453868f80 | 28 | else if (gobutton == 1) { |
Eggotape | 0:dcc453868f80 | 29 | maketea(state); |
Eggotape | 0:dcc453868f80 | 30 | } |
Eggotape | 0:dcc453868f80 | 31 | } |
Eggotape | 0:dcc453868f80 | 32 | } |
Eggotape | 0:dcc453868f80 | 33 | |
Eggotape | 0:dcc453868f80 | 34 | int set(int currentstate) { |
Eggotape | 0:dcc453868f80 | 35 | t.start(); |
Eggotape | 0:dcc453868f80 | 36 | while (gobutton != 1 and t < 10) { |
Eggotape | 0:dcc453868f80 | 37 | if (setbutton == 1) { |
Eggotape | 0:dcc453868f80 | 38 | currentstate = currentstate + 1; |
Eggotape | 0:dcc453868f80 | 39 | if (currentstate > 6) { |
Eggotape | 0:dcc453868f80 | 40 | currentstate = 1; |
Eggotape | 0:dcc453868f80 | 41 | } |
Eggotape | 0:dcc453868f80 | 42 | lcd.cls(); |
Eggotape | 0:dcc453868f80 | 43 | displaystate(currentstate); |
Eggotape | 0:dcc453868f80 | 44 | wait(0.25); |
Eggotape | 0:dcc453868f80 | 45 | t.reset(); |
Eggotape | 0:dcc453868f80 | 46 | t.start(); |
Eggotape | 0:dcc453868f80 | 47 | } |
Eggotape | 0:dcc453868f80 | 48 | } |
Eggotape | 0:dcc453868f80 | 49 | lcd.cls(); |
Eggotape | 0:dcc453868f80 | 50 | lcd.printf("Start?\n"); |
Eggotape | 0:dcc453868f80 | 51 | return currentstate; |
Eggotape | 0:dcc453868f80 | 52 | } |
Eggotape | 0:dcc453868f80 | 53 | |
Eggotape | 0:dcc453868f80 | 54 | int displaystate(int currentstate) { |
Eggotape | 0:dcc453868f80 | 55 | if (currentstate == 1) { |
Eggotape | 0:dcc453868f80 | 56 | lcd.printf("1 min - dip\n"); |
Eggotape | 0:dcc453868f80 | 57 | } |
Eggotape | 0:dcc453868f80 | 58 | else if (currentstate == 2) { |
Eggotape | 0:dcc453868f80 | 59 | lcd.printf("2 mins - dip\n"); |
Eggotape | 0:dcc453868f80 | 60 | } |
Eggotape | 0:dcc453868f80 | 61 | else if (currentstate == 3) { |
Eggotape | 0:dcc453868f80 | 62 | lcd.printf("3 mins - dip\n"); |
Eggotape | 0:dcc453868f80 | 63 | } |
Eggotape | 0:dcc453868f80 | 64 | else if (currentstate == 4) { |
Eggotape | 0:dcc453868f80 | 65 | lcd.printf("1 min - no dip\n"); |
Eggotape | 0:dcc453868f80 | 66 | } |
Eggotape | 0:dcc453868f80 | 67 | else if (currentstate == 5) { |
Eggotape | 0:dcc453868f80 | 68 | lcd.printf("2 mins - no dip\n"); |
Eggotape | 0:dcc453868f80 | 69 | } |
Eggotape | 0:dcc453868f80 | 70 | else if (currentstate == 6) { |
Eggotape | 0:dcc453868f80 | 71 | lcd.printf("3 mins - no dip\n"); |
Eggotape | 0:dcc453868f80 | 72 | } |
Eggotape | 0:dcc453868f80 | 73 | return 0; |
Eggotape | 0:dcc453868f80 | 74 | } |
Eggotape | 0:dcc453868f80 | 75 | |
Eggotape | 0:dcc453868f80 | 76 | int maketea(int currentstate) { |
Eggotape | 0:dcc453868f80 | 77 | lcd.cls(); |
Eggotape | 0:dcc453868f80 | 78 | lcd.printf("Brewing...\n"); |
Eggotape | 0:dcc453868f80 | 79 | displaystate(currentstate); |
Eggotape | 0:dcc453868f80 | 80 | int time; |
Eggotape | 0:dcc453868f80 | 81 | int dip; |
Eggotape | 0:dcc453868f80 | 82 | if (currentstate == 1) { |
Eggotape | 0:dcc453868f80 | 83 | time = 60; |
Eggotape | 0:dcc453868f80 | 84 | dip = 1; |
Eggotape | 0:dcc453868f80 | 85 | } |
Eggotape | 0:dcc453868f80 | 86 | else if (currentstate == 2) { |
Eggotape | 0:dcc453868f80 | 87 | time = 120; |
Eggotape | 0:dcc453868f80 | 88 | dip = 1; |
Eggotape | 0:dcc453868f80 | 89 | } |
Eggotape | 0:dcc453868f80 | 90 | else if (currentstate == 3) { |
Eggotape | 0:dcc453868f80 | 91 | time = 180; |
Eggotape | 0:dcc453868f80 | 92 | dip = 1; |
Eggotape | 0:dcc453868f80 | 93 | } |
Eggotape | 0:dcc453868f80 | 94 | else if (currentstate == 4) { |
Eggotape | 0:dcc453868f80 | 95 | time = 60; |
Eggotape | 0:dcc453868f80 | 96 | dip = 0; |
Eggotape | 0:dcc453868f80 | 97 | } |
Eggotape | 0:dcc453868f80 | 98 | else if (currentstate == 5) { |
Eggotape | 0:dcc453868f80 | 99 | time = 120; |
Eggotape | 0:dcc453868f80 | 100 | dip = 0; |
Eggotape | 0:dcc453868f80 | 101 | } |
Eggotape | 0:dcc453868f80 | 102 | else if (currentstate == 6) { |
Eggotape | 0:dcc453868f80 | 103 | time = 180; |
Eggotape | 0:dcc453868f80 | 104 | dip = 0; |
Eggotape | 0:dcc453868f80 | 105 | } |
Eggotape | 0:dcc453868f80 | 106 | myservo = 0; |
Eggotape | 0:dcc453868f80 | 107 | t.start(); |
Eggotape | 0:dcc453868f80 | 108 | while (t < time) { |
Eggotape | 0:dcc453868f80 | 109 | if (dip == 1) { |
Eggotape | 0:dcc453868f80 | 110 | dipping(); |
Eggotape | 0:dcc453868f80 | 111 | } |
Eggotape | 0:dcc453868f80 | 112 | } |
Eggotape | 0:dcc453868f80 | 113 | t.reset(); |
Eggotape | 0:dcc453868f80 | 114 | myservo = 1; |
Eggotape | 0:dcc453868f80 | 115 | lcd.cls(); |
Eggotape | 0:dcc453868f80 | 116 | lcd.printf("Done!\n"); |
Eggotape | 0:dcc453868f80 | 117 | wait(5); |
Eggotape | 0:dcc453868f80 | 118 | lcd.cls(); |
Eggotape | 0:dcc453868f80 | 119 | lcd.printf("Start?\n"); |
Eggotape | 0:dcc453868f80 | 120 | return 0; |
Eggotape | 0:dcc453868f80 | 121 | } |
Eggotape | 0:dcc453868f80 | 122 | |
Eggotape | 0:dcc453868f80 | 123 | int dipping() { |
Eggotape | 0:dcc453868f80 | 124 | myservo = 0.5; |
Eggotape | 0:dcc453868f80 | 125 | wait(1); |
Eggotape | 0:dcc453868f80 | 126 | myservo = 0; |
Eggotape | 0:dcc453868f80 | 127 | wait(1); |
Eggotape | 0:dcc453868f80 | 128 | return 0; |
Eggotape | 0:dcc453868f80 | 129 | } |