Project
Dependencies: 4DGL-uLCD-SE MAX31855 mbed-rtos mbed
Fork of Coffee_Roaster by
Diff: main.cpp
- Revision:
- 1:26267401354a
- Parent:
- 0:4fbaafa6574c
- Child:
- 2:c94244d1cab4
--- a/main.cpp Wed Nov 12 18:56:57 2014 +0000 +++ b/main.cpp Wed Nov 12 19:17:19 2014 +0000 @@ -9,24 +9,22 @@ max31855 max1(thermoSPI, p20); //setup max31855 interface Mutex lcd_mutex; // mutex to make the lcd lib thread safe Semaphore four_slots(1); //Activate semaphore -DigitalOut toggle(p30); -DigitalIn up(p19); -DigitalIn down(p18); +DigitalOut toggle(p30); // toggle for Nichrome wire SSR +DigitalIn up(p19); // User pushbutton up controller +DigitalIn down(p18); // User pushbutton down button controller -int settemp = 75; - +int settemp = 75; // initial temperature set float ftemperature = 0; // float variable for temperature float ctemperature = 0; // float variable for temperature -// Thread t1 -// print the elapsed time on line 1 of the uLCD (i.e., HH:MM:SS) -void elapsedtime(void const *args) { //line 2 - int s = 00; - int m = 00; - int h = 00; +// Thread 1: print the elapsed time on line 1 of the uLCD (i.e., HH:MM:SS) +void elapsedtime(void const *args) { //elapsed timer for when program starts + int s = 00; //seconds + int m = 00; //minutes + int h = 00; //hours while(true){ - s++; + s++; if(s>59){ s=00; m++; @@ -35,24 +33,21 @@ m=00; h++; } - four_slots.wait(); + four_slots.wait(); // lock screen resource //lcd_mutex.lock(); - uLCD.color(0xFFFF00); - uLCD.locate(0,0); //col,row - wait(0.1); - uLCD.printf("ET: %2d:%2d:%2d", h,m,s); + uLCD.color(0xFFFF00); //set text color + uLCD.locate(0,0); //col,row location of text + wait(0.1); + uLCD.printf("ET: %2d:%2d:%2d", h,m,s); // display time //lcd_mutex.unlock(); - four_slots.release(); + four_slots.release(); //unlock screen resource Thread::wait(1000); // update once per secon } } -// Thread t2 -// print the temperature from the thermocouple - MAX31855 device +// Thread 2: print the temperature from the thermocouple - MAX31855 device void thermoread(void const *args) { //line 2 - - while(true){ if (max1.ready()==1){ ctemperature = max1.read_temp(); //Get the reading @@ -64,19 +59,13 @@ uLCD.printf("Current Temp. F"); uLCD.locate(0,3); //col,row uLCD.printf("%4.2f", ftemperature); - - //uLCD.locate(0,5); //col,row - // uLCD.printf("Set Temp. F"); - // uLCD.locate(0,6); //col,row - // uLCD.printf("%d",settemp); - four_slots.release(); } } } - -void thermoset (void const *args) { //line 2 +// Thread 3: read in user input from buttons.. +void thermoset (void const *args) { // while(true){ if (up==1){ settemp += 1; @@ -104,22 +93,20 @@ } - int main() { max1.initialise(); //initialize thermocouple IC uLCD.baudrate(3000000); //set LCD baudrate Thread t1(elapsedtime); //run elapsed time counter Thread t2(thermoread); //read and display temperature from thermocouple - Thread t3(thermoset); - + Thread t3(thermoset); //runs thread that checks to see if user has changed the temperature setpoint - while(1){ //While so program doesn't end - if(ftemperature < settemp-1){ - toggle=1; //turn on ssr + while(1){ //hystersis program + if(ftemperature < settemp-1){ //condition for 1 degree under + toggle=1; //turn on ssr for nichrome wire } - if(ftemperature > settemp+1){ - toggle=0; + if(ftemperature > settemp+1){ //condition for 1 degree over + toggle=0; //turn off ssr for nichrome wire } - wait(1); + wait(1); //check every 1 second } -} \ No newline at end of file +}