Working better. Maybe a little more improvement needs to be made to the display algorithm.
Dependencies: 4DGL-uLCD-SE MAX31855 mbed-rtos mbed
Fork of Coffee_Roaster_testing by
Diff: main.cpp
- Revision:
- 9:d7300899fd85
- Parent:
- 8:1db15ab871a4
diff -r 1db15ab871a4 -r d7300899fd85 main.cpp --- a/main.cpp Thu Nov 20 20:30:51 2014 +0000 +++ b/main.cpp Tue Dec 02 18:10:09 2014 +0000 @@ -6,48 +6,35 @@ #include <mpr121.h> #include "Stopwatch.h" -DigitalOut led1(LED1); -DigitalOut led2(LED2); -DigitalOut led3(LED3); -DigitalOut led4(LED4); + +DigitalOut toggle(p30); // toggle for Nichrome wire SSR +DigitalIn up(p19); // User reset button DigitalOut motor(p22); // motor control uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; SPI thermoSPI(p5,p6,p7); // setup SPI interface max31855 max1(thermoSPI, p20); //setup max31855 interface +InterruptIn interrupt(p26); // Create the interrupt receiver object on pin 26 +I2C i2c(p28, p27); // Setup the i2c bus on pins 28 and 27 +Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); // Setup the Mpr121: // constructor(i2c object, i2c address of the mpr121) + Mutex lcd_mutex; // mutex to make the lcd lib thread safe Semaphore four_slots(1); //Activate semaphore -DigitalOut toggle(p30); // toggle for Nichrome wire SSR -DigitalIn up(p19); // User pushbutton up controller -DigitalIn down(p18); // User pushbutton down button controller +Stopwatch watch = Stopwatch(); - -int settemp = 85; // initial temperature set +int settemp = 1; // initial temperature set float ftemperature = 0; // float variable for temperature float ctemperature = 0; // float variable for temperature -int temptemp=85; - +int temptemp=1; int key_code=-1; int a =0; int place= 100; - int s = 00; int m = 00; int h = 00; -Stopwatch watch = Stopwatch(); -// Create the interrupt receiver object on pin 26 -InterruptIn interrupt(p26); - -// Setup the i2c bus on pins 28 and 27 -I2C i2c(p28, p27); - -// Setup the Mpr121: -// constructor(i2c object, i2c address of the mpr121) -Mpr121 mpr121(&i2c, Mpr121::ADD_VSS); - -// Thread 1: print the elapsed time on line 1 of the uLCD (i.e., HH:MM:SS) +// Thread 1: run stopwatch timer void elapsedtime(void const *args) //elapsed timer for when program starts { watch.start(); @@ -59,8 +46,8 @@ { while(true) { if (max1.ready()==1) { - ctemperature = max1.read_temp(); //Get the reading - ftemperature = (ctemperature)*(9.0/5.0)+32.0; + ctemperature = max1.read_temp(); //Get the reading in celsius + ftemperature = (ctemperature)*(9.0/5.0)+32.0; //Get the reading in fahrenheit } } } @@ -71,19 +58,19 @@ { while(true) { if(up == 1) { - a = 0; - temptemp=0; - while(a<3) { - if(key_code>=0 && key_code<=9) { - wait(.1); - if(a==0)temptemp=key_code*100; - if(a==1)temptemp+=key_code*10; - if(a==2)temptemp+=key_code*1; - a++; - key_code = -1; - } - } - settemp=temptemp; + a = 0; + temptemp=0; + while(a<3) { //USER MUST INPUT 3 NUMBERS + if(key_code>=0 && key_code<=9) { + wait(.1); + if(a==0)temptemp=key_code*100; + if(a==1)temptemp+=key_code*10; + if(a==2)temptemp+=key_code*1; + a++; + key_code = -1; //clear keycode + } + } + settemp=temptemp; } } } @@ -94,13 +81,10 @@ 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++) { + for (i=0; i<12; i++) { // puts key number out to 0-12 digits if (((value>>i)&0x01)==1) key_code=i; } - if(key_code== 10) { motor = 0; } @@ -114,10 +98,8 @@ { max1.initialise(); //initialize thermocouple IC uLCD.baudrate(3000000); //set LCD baudrate - interrupt.fall(&fallInterrupt); interrupt.mode(PullUp); - Thread t1(elapsedtime); //run elapsed time counter Thread t2(thermoread); //read and display temperature from thermocouple Thread t3(thermoset); // user set temperature @@ -126,37 +108,16 @@ char* time = watch.getTime(); four_slots.wait(); //lock screen uLCD.color(0xFFFF00); //set color - uLCD.locate(0,0); //col,row for time uLCD.printf("Time | %s",time);//%2d:%2d:%2d", h,m,s); // display time - uLCD.locate(0,5); uLCD.printf("Set | %3d",settemp); // current set temperature - uLCD.locate(0,6); uLCD.printf("Current | %4.2f", ftemperature); // temperature reading - uLCD.locate(0,2); uLCD.printf("Motor | "); //motor state in "on" or "off" state - uLCD.locate(0,13); uLCD.printf("New Temp| %3d",temptemp); //new user temperature - - /*if(a==0){ - uLCD.locate(11,13); - uLCD.printf("%d",temptemp); //new user temperature - } - - if(a==1){ - uLCD.locate(11,13); - uLCD.printf("%d",temptemp); //new user temperature - } - - if(a==2){ - uLCD.locate(11,13); - uLCD.printf("%d",temptemp); //new user temperature - }*/ - if(motor==0) { uLCD.locate(11,2); //col,row uLCD.printf("OFF"); @@ -165,12 +126,9 @@ uLCD.locate(11,2); //col,row uLCD.printf("ON "); } - four_slots.release(); // release screen resource - if(ftemperature < settemp-1) { //condition for 1 degree under toggle=1; //turn on ssr for nichrome wire - //toggle=0; } if(ftemperature > settemp-1) { toggle=0; //turn off ssr for nichrome wire