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 Eric Patterson

Revision:
2:c94244d1cab4
Parent:
1:26267401354a
Child:
3:0f0e79eff4a7
diff -r 26267401354a -r c94244d1cab4 main.cpp
--- a/main.cpp	Wed Nov 12 19:17:19 2014 +0000
+++ b/main.cpp	Thu Nov 13 01:21:06 2014 +0000
@@ -3,6 +3,12 @@
 #include "rtos.h"
 #include "stdio.h"
 #include "max31855.h"
+#include <mpr121.h>
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
 
 uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin;
 SPI thermoSPI(p5,p6,p7); // setup SPI interface
@@ -13,10 +19,22 @@
 DigitalIn up(p19); // User pushbutton up controller
 DigitalIn down(p18); // User pushbutton down button controller
 
-int settemp = 75; // initial temperature set
+int settemp = 85; // initial temperature set
 float ftemperature = 0; // float variable for temperature
 float ctemperature = 0; // float variable for temperature
 
+int key_code=0;
+
+// 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)
 void elapsedtime(void const *args) { //elapsed timer for when program starts
     int s = 00; //seconds
@@ -64,10 +82,46 @@
     }
 }
 
-// Thread 3: read in user input from buttons..
-void thermoset (void const *args) { //
-    while(true){
-        if (up==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+1;
+  }
+  led4=key_code & 0x01;
+  led3=(key_code>>1) & 0x01;
+  led2=(key_code>>2) & 0x01;
+  led1=(key_code>>3) & 0x01;
+}
+
+
+int main() {
+    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
+    
+    while(1){ //hystersis program
+        key_code = 0;
+        four_slots.wait();    
+        uLCD.color(0xFFFF00);
+        uLCD.locate(0,10); //col,row
+        //wait(0.1);
+        uLCD.printf("Test.");
+        uLCD.locate(0,11); //col,row
+        uLCD.printf("%2d", key_code);
+        four_slots.release(); 
+             
+        if (key_code == 1){
             settemp += 1;
             four_slots.wait();    
             uLCD.color(0xFFFF00);        
@@ -76,9 +130,9 @@
             uLCD.locate(0,6); //col,row
             uLCD.printf("%d",settemp);
             four_slots.release(); 
-            wait(.5);
+            //wait(.5);
         }
-        if (down==1){
+        if (key_code== 2){
             settemp -= 1;
             four_slots.wait();    
             uLCD.color(0xFFFF00);        
@@ -87,26 +141,15 @@
             uLCD.locate(0,6); //col,row
             uLCD.printf("%d",settemp);
             four_slots.release();
-            wait(.5); 
+            //wait(.5); 
         }
+    
+        if(ftemperature < settemp-1){ //condition for 1 degree under
+            toggle=1; //turn on ssr for nichrome wire
+        }
+        if(ftemperature > settemp+1){  //condition for 1 degree over
+            toggle=0; //turn off ssr for nichrome wire
+        }
+        // wait(.1); //check every 1 second
     }
 }
-
-
-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); //runs thread that checks to see if user has changed the temperature setpoint
-    
-    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){  //condition for 1 degree over
-                toggle=0; //turn off ssr for nichrome wire
-            }
-            wait(1); //check every 1 second
-        }
-}