![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
ECE4180 Final Project
Dependencies: 4DGL-uLCD-SE DS1820 PinDetect Speaker mbed
Fork of SousVide by
main.cpp@1:2d86c674a78b, 2016-12-04 (annotated)
- Committer:
- Mcplokqaws
- Date:
- Sun Dec 04 23:10:56 2016 +0000
- Revision:
- 1:2d86c674a78b
- Parent:
- 0:03ec282c2908
Sous Vide
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
feabhas | 0:03ec282c2908 | 1 | #include "mbed.h" |
Mcplokqaws | 1:2d86c674a78b | 2 | #include "uLCD_4DGL.h" |
Mcplokqaws | 1:2d86c674a78b | 3 | #include "Speaker.h" |
Mcplokqaws | 1:2d86c674a78b | 4 | #include "DS1820.h" |
Mcplokqaws | 1:2d86c674a78b | 5 | #include "PinDetect.h" |
Mcplokqaws | 1:2d86c674a78b | 6 | #include <time.h> |
Mcplokqaws | 1:2d86c674a78b | 7 | |
Mcplokqaws | 1:2d86c674a78b | 8 | //Program by: Tianhang Ren, Minsuk Chun, Richard Lee |
Mcplokqaws | 1:2d86c674a78b | 9 | |
Mcplokqaws | 1:2d86c674a78b | 10 | //////////////////////////////////////////////////////// |
Mcplokqaws | 1:2d86c674a78b | 11 | //Initialize |
Mcplokqaws | 1:2d86c674a78b | 12 | /////////////////////////////////////////////////////// |
feabhas | 0:03ec282c2908 | 13 | |
Mcplokqaws | 1:2d86c674a78b | 14 | DS1820 probe(p5); |
Mcplokqaws | 1:2d86c674a78b | 15 | PinDetect pbUp(p18); // Buttons to raise/lower/enter temperature |
Mcplokqaws | 1:2d86c674a78b | 16 | PinDetect pbDown(p19); |
Mcplokqaws | 1:2d86c674a78b | 17 | PinDetect pbEnter (p20); |
Mcplokqaws | 1:2d86c674a78b | 18 | Serial pc(USBTX, USBRX); // serial comms over usb back to console |
Mcplokqaws | 1:2d86c674a78b | 19 | //Timer T; |
Mcplokqaws | 1:2d86c674a78b | 20 | DigitalOut myled1(LED1); // On when relay is engaged |
Mcplokqaws | 1:2d86c674a78b | 21 | DigitalOut myled2(LED2); |
Mcplokqaws | 1:2d86c674a78b | 22 | DigitalOut myled3(LED3); |
Mcplokqaws | 1:2d86c674a78b | 23 | DigitalOut myled4(LED4); |
Mcplokqaws | 1:2d86c674a78b | 24 | uLCD_4DGL uLCD(p28, p27, p29); // create a global uLCD object |
feabhas | 0:03ec282c2908 | 25 | |
Mcplokqaws | 1:2d86c674a78b | 26 | DigitalOut ctrl(p8); //relay control |
Mcplokqaws | 1:2d86c674a78b | 27 | |
Mcplokqaws | 1:2d86c674a78b | 28 | // setup instance of new Speaker class, mySpeaker using pin 21 |
Mcplokqaws | 1:2d86c674a78b | 29 | // the pin must be a PWM output pin |
Mcplokqaws | 1:2d86c674a78b | 30 | Speaker mySpeaker(p26); |
Mcplokqaws | 1:2d86c674a78b | 31 | |
Mcplokqaws | 1:2d86c674a78b | 32 | float userTemp = 0; //user desired temperature of device |
Mcplokqaws | 1:2d86c674a78b | 33 | int check = 0; //indicates whether enter key is pressed |
Mcplokqaws | 1:2d86c674a78b | 34 | float timeCook = 0; |
Mcplokqaws | 1:2d86c674a78b | 35 | |
feabhas | 0:03ec282c2908 | 36 | |
Mcplokqaws | 1:2d86c674a78b | 37 | //////////////////////////////////////////////////////// |
Mcplokqaws | 1:2d86c674a78b | 38 | // Initialize pushbuttons |
Mcplokqaws | 1:2d86c674a78b | 39 | /////////////////////////////////////////////////////// |
Mcplokqaws | 1:2d86c674a78b | 40 | |
Mcplokqaws | 1:2d86c674a78b | 41 | |
Mcplokqaws | 1:2d86c674a78b | 42 | // Callback routine is interrupt activated by a debounced pb1 hit |
Mcplokqaws | 1:2d86c674a78b | 43 | void pbUp_hit_callback (void) |
Mcplokqaws | 1:2d86c674a78b | 44 | { |
Mcplokqaws | 1:2d86c674a78b | 45 | // CODE HERE WILL RUN WHEN INTERUPT IS GENERATED |
Mcplokqaws | 1:2d86c674a78b | 46 | myled1 = !myled1; |
Mcplokqaws | 1:2d86c674a78b | 47 | mySpeaker.PlayNote(200.0,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 48 | userTemp++; |
Mcplokqaws | 1:2d86c674a78b | 49 | timeCook +=5; //TODO CHANGE TIME BACK TO 10 INTERVALS |
Mcplokqaws | 1:2d86c674a78b | 50 | } |
Mcplokqaws | 1:2d86c674a78b | 51 | |
Mcplokqaws | 1:2d86c674a78b | 52 | // Callback routine is interrupt activated by a debounced pb2 hit |
Mcplokqaws | 1:2d86c674a78b | 53 | void pbDown_hit_callback (void) |
Mcplokqaws | 1:2d86c674a78b | 54 | { |
Mcplokqaws | 1:2d86c674a78b | 55 | // CODE HERE WILL RUN WHEN INTERUPT IS GENERATED |
Mcplokqaws | 1:2d86c674a78b | 56 | myled2 = !myled2; |
Mcplokqaws | 1:2d86c674a78b | 57 | mySpeaker.PlayNote(400.0,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 58 | userTemp--; |
Mcplokqaws | 1:2d86c674a78b | 59 | if (userTemp <=0) { |
Mcplokqaws | 1:2d86c674a78b | 60 | userTemp = 0; |
feabhas | 0:03ec282c2908 | 61 | } |
Mcplokqaws | 1:2d86c674a78b | 62 | timeCook-=5; |
Mcplokqaws | 1:2d86c674a78b | 63 | if (timeCook <=0) |
Mcplokqaws | 1:2d86c674a78b | 64 | timeCook=0; |
Mcplokqaws | 1:2d86c674a78b | 65 | } |
Mcplokqaws | 1:2d86c674a78b | 66 | // Callback routine is interrupt activated by a debounced pb3 hit |
Mcplokqaws | 1:2d86c674a78b | 67 | void pbEnter_hit_callback (void) |
Mcplokqaws | 1:2d86c674a78b | 68 | { |
Mcplokqaws | 1:2d86c674a78b | 69 | // CODE HERE WILL RUN WHEN INTERUPT IS GENERATED |
Mcplokqaws | 1:2d86c674a78b | 70 | myled3 = !myled3; |
Mcplokqaws | 1:2d86c674a78b | 71 | mySpeaker.PlayNote(800.0,0.10,0.1); |
Mcplokqaws | 1:2d86c674a78b | 72 | mySpeaker.PlayNote(1000.0,0.10,0.1); |
Mcplokqaws | 1:2d86c674a78b | 73 | mySpeaker.PlayNote(1200.0,0.10,0.1); |
Mcplokqaws | 1:2d86c674a78b | 74 | check++; |
feabhas | 0:03ec282c2908 | 75 | } |
feabhas | 0:03ec282c2908 | 76 | |
Mcplokqaws | 1:2d86c674a78b | 77 | //////////////////////////////////////////////////////// |
Mcplokqaws | 1:2d86c674a78b | 78 | // Main method starts here |
Mcplokqaws | 1:2d86c674a78b | 79 | //////////////////////////////////////////////////////// |
Mcplokqaws | 1:2d86c674a78b | 80 | |
Mcplokqaws | 1:2d86c674a78b | 81 | int main() |
Mcplokqaws | 1:2d86c674a78b | 82 | { |
Mcplokqaws | 1:2d86c674a78b | 83 | //setup three SPST push buttons |
Mcplokqaws | 1:2d86c674a78b | 84 | pbUp.mode(PullUp); //add internal pullup resistor |
Mcplokqaws | 1:2d86c674a78b | 85 | pbDown.mode(PullUp); |
Mcplokqaws | 1:2d86c674a78b | 86 | pbEnter.mode(PullUp); |
Mcplokqaws | 1:2d86c674a78b | 87 | |
Mcplokqaws | 1:2d86c674a78b | 88 | // Delay for initial pullup to take effect |
Mcplokqaws | 1:2d86c674a78b | 89 | wait(.01); |
Mcplokqaws | 1:2d86c674a78b | 90 | |
Mcplokqaws | 1:2d86c674a78b | 91 | // Setup Interrupt callback functions for a pb hit |
Mcplokqaws | 1:2d86c674a78b | 92 | pbUp.attach_deasserted(&pbUp_hit_callback); |
Mcplokqaws | 1:2d86c674a78b | 93 | pbDown.attach_deasserted(&pbDown_hit_callback); |
Mcplokqaws | 1:2d86c674a78b | 94 | pbEnter.attach_deasserted(&pbEnter_hit_callback); |
Mcplokqaws | 1:2d86c674a78b | 95 | |
Mcplokqaws | 1:2d86c674a78b | 96 | // Start sampling pb inputs using interrupts |
Mcplokqaws | 1:2d86c674a78b | 97 | pbUp.setSampleFrequency(); |
Mcplokqaws | 1:2d86c674a78b | 98 | pbDown.setSampleFrequency(); |
Mcplokqaws | 1:2d86c674a78b | 99 | pbEnter.setSampleFrequency(); |
Mcplokqaws | 1:2d86c674a78b | 100 | |
Mcplokqaws | 1:2d86c674a78b | 101 | // pushbuttons now setup and running |
Mcplokqaws | 1:2d86c674a78b | 102 | |
Mcplokqaws | 1:2d86c674a78b | 103 | //////////////////////////////////////////////////////// |
Mcplokqaws | 1:2d86c674a78b | 104 | // Ask for temperature and time desired |
Mcplokqaws | 1:2d86c674a78b | 105 | //////////////////////////////////////////////////////// |
Mcplokqaws | 1:2d86c674a78b | 106 | |
Mcplokqaws | 1:2d86c674a78b | 107 | uLCD.printf("Enter desired temperature"); //Ask for desired temperature |
Mcplokqaws | 1:2d86c674a78b | 108 | while(check ==0) { //if check flag is 0, means enter has not been pushed |
Mcplokqaws | 1:2d86c674a78b | 109 | if (pbUp) { |
Mcplokqaws | 1:2d86c674a78b | 110 | uLCD.locate(0,3); |
Mcplokqaws | 1:2d86c674a78b | 111 | uLCD.printf("%4.0f", userTemp); |
Mcplokqaws | 1:2d86c674a78b | 112 | } |
Mcplokqaws | 1:2d86c674a78b | 113 | if (pbDown) { |
Mcplokqaws | 1:2d86c674a78b | 114 | uLCD.locate(0,3); |
Mcplokqaws | 1:2d86c674a78b | 115 | uLCD.printf("%4.0f", userTemp); |
Mcplokqaws | 1:2d86c674a78b | 116 | } |
Mcplokqaws | 1:2d86c674a78b | 117 | } |
Mcplokqaws | 1:2d86c674a78b | 118 | |
Mcplokqaws | 1:2d86c674a78b | 119 | float finalTemp = userTemp; //reassign to final temp |
Mcplokqaws | 1:2d86c674a78b | 120 | check = 0; |
Mcplokqaws | 1:2d86c674a78b | 121 | uLCD.cls(); |
Mcplokqaws | 1:2d86c674a78b | 122 | uLCD.locate(0,0); |
Mcplokqaws | 1:2d86c674a78b | 123 | timeCook = 0; //reset timeCook |
Mcplokqaws | 1:2d86c674a78b | 124 | uLCD.printf("Enter cooking time"); //Cooking time in minutes |
Mcplokqaws | 1:2d86c674a78b | 125 | while (check == 0) { |
Mcplokqaws | 1:2d86c674a78b | 126 | if (pbUp) { |
Mcplokqaws | 1:2d86c674a78b | 127 | uLCD.locate(0,3); |
Mcplokqaws | 1:2d86c674a78b | 128 | uLCD.printf("%4.0f", timeCook); |
Mcplokqaws | 1:2d86c674a78b | 129 | } |
Mcplokqaws | 1:2d86c674a78b | 130 | if (pbDown) { |
Mcplokqaws | 1:2d86c674a78b | 131 | uLCD.locate(0,3); |
Mcplokqaws | 1:2d86c674a78b | 132 | uLCD.printf("%4.0f", timeCook); |
Mcplokqaws | 1:2d86c674a78b | 133 | } |
Mcplokqaws | 1:2d86c674a78b | 134 | } |
Mcplokqaws | 1:2d86c674a78b | 135 | float finalTime = timeCook *60; //reassign to final time |
Mcplokqaws | 1:2d86c674a78b | 136 | ctrl = 1; // Turn on relay |
Mcplokqaws | 1:2d86c674a78b | 137 | float tempLimit = 0; //intitialize variable to track temperature |
Mcplokqaws | 1:2d86c674a78b | 138 | uLCD.locate(0,0); |
Mcplokqaws | 1:2d86c674a78b | 139 | uLCD.printf("Set Temp (C)", finalTemp); //print set temperature |
Mcplokqaws | 1:2d86c674a78b | 140 | while (tempLimit < (finalTemp + 1)) { //Loop while temperature is 1 degrees over destination |
Mcplokqaws | 1:2d86c674a78b | 141 | probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready |
Mcplokqaws | 1:2d86c674a78b | 142 | tempLimit = probe.temperature(); |
Mcplokqaws | 1:2d86c674a78b | 143 | uLCD.locate(0,3); |
Mcplokqaws | 1:2d86c674a78b | 144 | uLCD.printf("It is %3.1foC\r", probe.temperature()); |
Mcplokqaws | 1:2d86c674a78b | 145 | wait(1); |
Mcplokqaws | 1:2d86c674a78b | 146 | } |
Mcplokqaws | 1:2d86c674a78b | 147 | //////////////////////////////////////////////////////// |
Mcplokqaws | 1:2d86c674a78b | 148 | // Start cooking with finalized temperatures and time |
Mcplokqaws | 1:2d86c674a78b | 149 | //////////////////////////////////////////////////////// |
Mcplokqaws | 1:2d86c674a78b | 150 | |
Mcplokqaws | 1:2d86c674a78b | 151 | //PLAY SOUND FROM SPEAKER |
Mcplokqaws | 1:2d86c674a78b | 152 | /* T.start(); //Timer start (s)*/ |
Mcplokqaws | 1:2d86c674a78b | 153 | float time_remaining = 1; |
Mcplokqaws | 1:2d86c674a78b | 154 | ctrl = 0; |
Mcplokqaws | 1:2d86c674a78b | 155 | uLCD.cls(); |
Mcplokqaws | 1:2d86c674a78b | 156 | uLCD.locate(0,0); |
Mcplokqaws | 1:2d86c674a78b | 157 | uLCD.printf("Set Temperature %4.0foC\r", finalTemp); |
Mcplokqaws | 1:2d86c674a78b | 158 | set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
Mcplokqaws | 1:2d86c674a78b | 159 | // time_t seconds = time(NULL); |
Mcplokqaws | 1:2d86c674a78b | 160 | |
Mcplokqaws | 1:2d86c674a78b | 161 | while(time_remaining > 0) { //Loop while timer has not reached desired time |
Mcplokqaws | 1:2d86c674a78b | 162 | if (tempLimit < (finalTemp - 1)) { //If temperature is 2 degrees C lower than desired, turn relay on |
Mcplokqaws | 1:2d86c674a78b | 163 | ctrl = 1; |
Mcplokqaws | 1:2d86c674a78b | 164 | } else if (tempLimit >= finalTemp) { |
Mcplokqaws | 1:2d86c674a78b | 165 | ctrl = 0; |
Mcplokqaws | 1:2d86c674a78b | 166 | } |
Mcplokqaws | 1:2d86c674a78b | 167 | tempLimit = probe.temperature(); |
Mcplokqaws | 1:2d86c674a78b | 168 | probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready |
Mcplokqaws | 1:2d86c674a78b | 169 | uLCD.locate(0,3); |
Mcplokqaws | 1:2d86c674a78b | 170 | uLCD.printf("It is %3.1foC\r", probe.temperature()); |
Mcplokqaws | 1:2d86c674a78b | 171 | uLCD.locate(0,5); |
Mcplokqaws | 1:2d86c674a78b | 172 | time_t seconds = time(NULL); //Cycle RTC |
Mcplokqaws | 1:2d86c674a78b | 173 | time_remaining = finalTime - (seconds - 1256729737); |
Mcplokqaws | 1:2d86c674a78b | 174 | |
Mcplokqaws | 1:2d86c674a78b | 175 | if ((time_remaining/3600) >= 1 ) |
Mcplokqaws | 1:2d86c674a78b | 176 | uLCD.printf("Time remaining: \n%4.0f hours", time_remaining/3600); |
Mcplokqaws | 1:2d86c674a78b | 177 | else if ((time_remaining/60) >= 1) |
Mcplokqaws | 1:2d86c674a78b | 178 | uLCD.printf("Time remaining: %4.0f minutes", time_remaining/60); |
Mcplokqaws | 1:2d86c674a78b | 179 | else |
Mcplokqaws | 1:2d86c674a78b | 180 | uLCD.printf("Time remaining: %4.0f seconds", time_remaining); |
Mcplokqaws | 1:2d86c674a78b | 181 | } |
Mcplokqaws | 1:2d86c674a78b | 182 | |
Mcplokqaws | 1:2d86c674a78b | 183 | ctrl = 0; |
Mcplokqaws | 1:2d86c674a78b | 184 | |
Mcplokqaws | 1:2d86c674a78b | 185 | //PLAY SOUND FROM SPEAKER |
Mcplokqaws | 1:2d86c674a78b | 186 | mySpeaker.PlayNote(1567.98,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 187 | mySpeaker.PlayNote(1046.50,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 188 | mySpeaker.PlayNote(1174.66,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 189 | mySpeaker.PlayNote(1318.51,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 190 | mySpeaker.PlayNote(1396.91,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 191 | mySpeaker.PlayNote(1567.98,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 192 | mySpeaker.PlayNote(1046.50,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 193 | mySpeaker.PlayNote(1046.50,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 194 | mySpeaker.PlayNote(1760.00,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 195 | mySpeaker.PlayNote(1396.91,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 196 | mySpeaker.PlayNote(1567.98,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 197 | mySpeaker.PlayNote(1760.00,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 198 | mySpeaker.PlayNote(1975.53,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 199 | mySpeaker.PlayNote(2093.00,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 200 | mySpeaker.PlayNote(1046.50,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 201 | mySpeaker.PlayNote(1046.50,0.25,0.1); |
Mcplokqaws | 1:2d86c674a78b | 202 | |
Mcplokqaws | 1:2d86c674a78b | 203 | uLCD.cls(); |
Mcplokqaws | 1:2d86c674a78b | 204 | uLCD.locate(0,0); |
Mcplokqaws | 1:2d86c674a78b | 205 | uLCD.printf("Food is ready"); |
Mcplokqaws | 1:2d86c674a78b | 206 | } |
Mcplokqaws | 1:2d86c674a78b | 207 |