Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE DS1820 PinDetect Speaker mbed
Fork of SousVide by
main.cpp
00001 #include "mbed.h" 00002 #include "uLCD_4DGL.h" 00003 #include "Speaker.h" 00004 #include "DS1820.h" 00005 #include "PinDetect.h" 00006 #include <time.h> 00007 00008 //Program by: Tianhang Ren, Minsuk Chun, Richard Lee 00009 00010 //////////////////////////////////////////////////////// 00011 //Initialize 00012 /////////////////////////////////////////////////////// 00013 00014 DS1820 probe(p5); 00015 PinDetect pbUp(p18); // Buttons to raise/lower/enter temperature 00016 PinDetect pbDown(p19); 00017 PinDetect pbEnter (p20); 00018 Serial pc(USBTX, USBRX); // serial comms over usb back to console 00019 //Timer T; 00020 DigitalOut myled1(LED1); // On when relay is engaged 00021 DigitalOut myled2(LED2); 00022 DigitalOut myled3(LED3); 00023 DigitalOut myled4(LED4); 00024 uLCD_4DGL uLCD(p28, p27, p29); // create a global uLCD object 00025 00026 DigitalOut ctrl(p8); //relay control 00027 00028 // setup instance of new Speaker class, mySpeaker using pin 21 00029 // the pin must be a PWM output pin 00030 Speaker mySpeaker(p26); 00031 00032 float userTemp = 0; //user desired temperature of device 00033 int check = 0; //indicates whether enter key is pressed 00034 float timeCook = 0; 00035 00036 00037 //////////////////////////////////////////////////////// 00038 // Initialize pushbuttons 00039 /////////////////////////////////////////////////////// 00040 00041 00042 // Callback routine is interrupt activated by a debounced pb1 hit 00043 void pbUp_hit_callback (void) 00044 { 00045 // CODE HERE WILL RUN WHEN INTERUPT IS GENERATED 00046 myled1 = !myled1; 00047 mySpeaker.PlayNote(200.0,0.25,0.1); 00048 userTemp++; 00049 timeCook +=5; //TODO CHANGE TIME BACK TO 10 INTERVALS 00050 } 00051 00052 // Callback routine is interrupt activated by a debounced pb2 hit 00053 void pbDown_hit_callback (void) 00054 { 00055 // CODE HERE WILL RUN WHEN INTERUPT IS GENERATED 00056 myled2 = !myled2; 00057 mySpeaker.PlayNote(400.0,0.25,0.1); 00058 userTemp--; 00059 if (userTemp <=0) { 00060 userTemp = 0; 00061 } 00062 timeCook-=5; 00063 if (timeCook <=0) 00064 timeCook=0; 00065 } 00066 // Callback routine is interrupt activated by a debounced pb3 hit 00067 void pbEnter_hit_callback (void) 00068 { 00069 // CODE HERE WILL RUN WHEN INTERUPT IS GENERATED 00070 myled3 = !myled3; 00071 mySpeaker.PlayNote(800.0,0.10,0.1); 00072 mySpeaker.PlayNote(1000.0,0.10,0.1); 00073 mySpeaker.PlayNote(1200.0,0.10,0.1); 00074 check++; 00075 } 00076 00077 //////////////////////////////////////////////////////// 00078 // Main method starts here 00079 //////////////////////////////////////////////////////// 00080 00081 int main() 00082 { 00083 //setup three SPST push buttons 00084 pbUp.mode(PullUp); //add internal pullup resistor 00085 pbDown.mode(PullUp); 00086 pbEnter.mode(PullUp); 00087 00088 // Delay for initial pullup to take effect 00089 wait(.01); 00090 00091 // Setup Interrupt callback functions for a pb hit 00092 pbUp.attach_deasserted(&pbUp_hit_callback); 00093 pbDown.attach_deasserted(&pbDown_hit_callback); 00094 pbEnter.attach_deasserted(&pbEnter_hit_callback); 00095 00096 // Start sampling pb inputs using interrupts 00097 pbUp.setSampleFrequency(); 00098 pbDown.setSampleFrequency(); 00099 pbEnter.setSampleFrequency(); 00100 00101 // pushbuttons now setup and running 00102 00103 //////////////////////////////////////////////////////// 00104 // Ask for temperature and time desired 00105 //////////////////////////////////////////////////////// 00106 00107 uLCD.printf("Enter desired temperature"); //Ask for desired temperature 00108 while(check ==0) { //if check flag is 0, means enter has not been pushed 00109 if (pbUp) { 00110 uLCD.locate(0,3); 00111 uLCD.printf("%4.0f", userTemp); 00112 } 00113 if (pbDown) { 00114 uLCD.locate(0,3); 00115 uLCD.printf("%4.0f", userTemp); 00116 } 00117 } 00118 00119 float finalTemp = userTemp; //reassign to final temp 00120 check = 0; 00121 uLCD.cls(); 00122 uLCD.locate(0,0); 00123 timeCook = 0; //reset timeCook 00124 uLCD.printf("Enter cooking time"); //Cooking time in minutes 00125 while (check == 0) { 00126 if (pbUp) { 00127 uLCD.locate(0,3); 00128 uLCD.printf("%4.0f", timeCook); 00129 } 00130 if (pbDown) { 00131 uLCD.locate(0,3); 00132 uLCD.printf("%4.0f", timeCook); 00133 } 00134 } 00135 float finalTime = timeCook *60; //reassign to final time 00136 ctrl = 1; // Turn on relay 00137 float tempLimit = 0; //intitialize variable to track temperature 00138 uLCD.locate(0,0); 00139 uLCD.printf("Set Temp (C)", finalTemp); //print set temperature 00140 while (tempLimit < (finalTemp + 1)) { //Loop while temperature is 1 degrees over destination 00141 probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready 00142 tempLimit = probe.temperature(); 00143 uLCD.locate(0,3); 00144 uLCD.printf("It is %3.1foC\r", probe.temperature()); 00145 wait(1); 00146 } 00147 //////////////////////////////////////////////////////// 00148 // Start cooking with finalized temperatures and time 00149 //////////////////////////////////////////////////////// 00150 00151 //PLAY SOUND FROM SPEAKER 00152 /* T.start(); //Timer start (s)*/ 00153 float time_remaining = 1; 00154 ctrl = 0; 00155 uLCD.cls(); 00156 uLCD.locate(0,0); 00157 uLCD.printf("Set Temperature %4.0foC\r", finalTemp); 00158 set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 00159 // time_t seconds = time(NULL); 00160 00161 while(time_remaining > 0) { //Loop while timer has not reached desired time 00162 if (tempLimit < (finalTemp - 1)) { //If temperature is 2 degrees C lower than desired, turn relay on 00163 ctrl = 1; 00164 } else if (tempLimit >= finalTemp) { 00165 ctrl = 0; 00166 } 00167 tempLimit = probe.temperature(); 00168 probe.convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready 00169 uLCD.locate(0,3); 00170 uLCD.printf("It is %3.1foC\r", probe.temperature()); 00171 uLCD.locate(0,5); 00172 time_t seconds = time(NULL); //Cycle RTC 00173 time_remaining = finalTime - (seconds - 1256729737); 00174 00175 if ((time_remaining/3600) >= 1 ) 00176 uLCD.printf("Time remaining: \n%4.0f hours", time_remaining/3600); 00177 else if ((time_remaining/60) >= 1) 00178 uLCD.printf("Time remaining: %4.0f minutes", time_remaining/60); 00179 else 00180 uLCD.printf("Time remaining: %4.0f seconds", time_remaining); 00181 } 00182 00183 ctrl = 0; 00184 00185 //PLAY SOUND FROM SPEAKER 00186 mySpeaker.PlayNote(1567.98,0.25,0.1); 00187 mySpeaker.PlayNote(1046.50,0.25,0.1); 00188 mySpeaker.PlayNote(1174.66,0.25,0.1); 00189 mySpeaker.PlayNote(1318.51,0.25,0.1); 00190 mySpeaker.PlayNote(1396.91,0.25,0.1); 00191 mySpeaker.PlayNote(1567.98,0.25,0.1); 00192 mySpeaker.PlayNote(1046.50,0.25,0.1); 00193 mySpeaker.PlayNote(1046.50,0.25,0.1); 00194 mySpeaker.PlayNote(1760.00,0.25,0.1); 00195 mySpeaker.PlayNote(1396.91,0.25,0.1); 00196 mySpeaker.PlayNote(1567.98,0.25,0.1); 00197 mySpeaker.PlayNote(1760.00,0.25,0.1); 00198 mySpeaker.PlayNote(1975.53,0.25,0.1); 00199 mySpeaker.PlayNote(2093.00,0.25,0.1); 00200 mySpeaker.PlayNote(1046.50,0.25,0.1); 00201 mySpeaker.PlayNote(1046.50,0.25,0.1); 00202 00203 uLCD.cls(); 00204 uLCD.locate(0,0); 00205 uLCD.printf("Food is ready"); 00206 } 00207
Generated on Sat Jul 16 2022 02:55:00 by
1.7.2
