Project
Dependencies: 4DGL-uLCD-SE MAX31855 mbed-rtos mbed
Fork of Coffee_Roaster by
Diff: main.cpp
- Revision:
- 6:076572f58a5e
- Parent:
- 5:4c4a3e2b8582
- Child:
- 7:8a0223a951c1
diff -r 4c4a3e2b8582 -r 076572f58a5e main.cpp --- a/main.cpp Wed Nov 19 21:43:51 2014 +0000 +++ b/main.cpp Wed Nov 19 23:34:27 2014 +0000 @@ -8,7 +8,7 @@ DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); -DigitalOut led4(LED4); +DigitalOut led4(LED4); DigitalOut motor(p22); // motor control uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; @@ -24,6 +24,7 @@ int settemp = 85; // initial temperature set float ftemperature = 0; // float variable for temperature float ctemperature = 0; // float variable for temperature +int temptemp=0; int key_code=0; @@ -39,26 +40,27 @@ Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); // 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 +void elapsedtime(void const *args) //elapsed timer for when program starts +{ int s = 00; //seconds - int m = 00; //minutes + int m = 00; //minutes int h = 00; //hours - - while(true){ - s++; - if(s>59){ - s=00; - m++; - } - if(m>59){ - m=00; - h++; - } - four_slots.wait(); // lock screen resource - //lcd_mutex.lock(); + + while(true) { + s++; + if(s>59) { + s=00; + m++; + } + if(m>59) { + m=00; + h++; + } + four_slots.wait(); // lock screen resource + //lcd_mutex.lock(); uLCD.color(0xFFFF00); //set text color uLCD.locate(0,0); //col,row location of text - wait(0.1); + wait(0.1); uLCD.printf("Time | %2d:%2d:%2d", h,m,s); // display time //lcd_mutex.unlock(); four_slots.release(); //unlock screen resource @@ -68,108 +70,129 @@ // Thread 2: print the temperature from the thermocouple - MAX31855 device -void thermoread(void const *args) { //line 2 - while(true){ - if (max1.ready()==1){ +void thermoread(void const *args) //line 2 +{ + while(true) { + if (max1.ready()==1) { ctemperature = max1.read_temp(); //Get the reading ftemperature = (ctemperature)*(9.0/5.0)+32.0; - four_slots.wait(); + four_slots.wait(); uLCD.color(0xFFFF00); //uLCD.locate(0,2); //col,row //wait(0.1); - // uLCD.printf("Current Temp. F"); + // uLCD.printf("Current Temp. F"); uLCD.locate(11,6); //col,row uLCD.printf("%4.2f", ftemperature); - four_slots.release(); + four_slots.release(); } } } -void fallInterrupt() { - int i=0; - int value=mpr121.read(0x00); - value +=mpr121.read(0x01)<<8; - // LED demo mod - i=0; - // puts key number out to LEDs for demo - for (i=0; i<12; i++) { - if (((value>>i)&0x01)==1) key_code=i+1; - } +void fallInterrupt() +{ + int i=0; + int value=mpr121.read(0x00); + value +=mpr121.read(0x01)<<8; + // LED demo mod + i=0; + // puts key number out to LEDs for demo + for (i=0; i<12; i++) { + if (((value>>i)&0x01)==1) key_code=i; + } + + if(key_code== 10) { + motor = 0; + + + } + if(key_code== 11) { + motor = 1; + } } +int a =0; +int main() +{ + max1.initialise(); //initialize thermocouple IC + uLCD.baudrate(3000000); //set LCD baudrate -int main() { - max1.initialise(); //initialize thermocouple IC - uLCD.baudrate(3000000); //set LCD baudrate - - // four_slots.wait(); + + + interrupt.fall(&fallInterrupt); + interrupt.mode(PullUp); + + Thread t1(elapsedtime); //run elapsed time counter + Thread t2(thermoread); //read and display temperature from thermocouple + + while(1) { //hystersis program + key_code = 0; + + four_slots.wait(); uLCD.color(0xFFFF00); uLCD.locate(0,5); //col,row uLCD.printf("Set | "); uLCD.locate(0,6); //col,row uLCD.printf("Current | "); - uLCD.locate(11,5); //col,row - uLCD.printf("85"); uLCD.locate(0,2); //col,row - uLCD.printf("Motor | OFF"); - // four_slots.release(); - - interrupt.fall(&fallInterrupt); - interrupt.mode(PullUp); - - Thread t1(elapsedtime); //run elapsed time counter - Thread t2(thermoread); //read and display temperature from thermocouple - - while(1){ //hystersis program - key_code = 0; - - - - if(key_code == 2){ - settemp += 1; - four_slots.wait(); - uLCD.color(0xFFFF00); - uLCD.locate(11,5); //col,row - uLCD.printf("%d",settemp); - four_slots.release(); - wait(2); - } - if(key_code== 1){ - settemp -= 1; - four_slots.wait(); - uLCD.color(0xFFFF00); - uLCD.locate(11,5); //col,row - uLCD.printf("%d",settemp); - four_slots.release(); - } - - if(key_code== 9){ - motor = 0; - settemp -= 1; - four_slots.wait(); - uLCD.color(0xFFFF00); + uLCD.printf("Motor | "); + four_slots.release(); + + int place= 100; + + if(motor==0) { + four_slots.wait(); + uLCD.color(0xFFFF00); uLCD.locate(11,2); //col,row uLCD.printf("OFF"); four_slots.release(); } - if(key_code== 10){ - motor = 1; - settemp -= 1; - four_slots.wait(); - uLCD.color(0xFFFF00); + if(motor==1) { + four_slots.wait(); + uLCD.color(0xFFFF00); uLCD.locate(11,2); //col,row - uLCD.printf(" ON "); + uLCD.printf("ON "); four_slots.release(); } - - if(ftemperature < settemp-1){ //condition for 1 degree under + + + if(a<3) { + //key_code = -1; + if(key_code>=0 && key_code<=9) { + temptemp+=place*key_code; + place=place/10; + four_slots.wait(); + uLCD.color(0xFFFF00); + uLCD.locate(0,13); //col,row + uLCD.printf("intermediate value"); + uLCD.locate(0,14); //col,row + uLCD.printf("%3d",temptemp); + four_slots.release(); + a++; + wait(2); + } + } + if(up == 1) { + a = 0; + } + settemp=temptemp; + temptemp=0; + four_slots.wait(); + uLCD.color(0xFFFF00); + uLCD.locate(11,5); //col,row + uLCD.printf("%3d",settemp); + four_slots.release(); + wait(2); + + + + if(ftemperature < settemp-1) { //condition for 1 degree under toggle=1; //turn on ssr for nichrome wire toggle=0; } - // if(ftemperature > settemp-1){ //condition for 1 degree over + // if(ftemperature > settemp-1){ //condition for 1 degree over // toggle=0; //turn off ssr for nichrome wire - // } + // } // wait(.1); //check every 1 second } }