Interrupt with character limit

Dependencies:   mbed

Fork of Temperature_Reading1 by jack kemnitz

Files at this revision

API Documentation at this revision

Comitter:
iwolf32
Date:
Thu Aug 31 14:08:54 2017 +0000
Parent:
1:1de97b1145f3
Commit message:
Temp Interrupt with limit

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1de97b1145f3 -r d9fa8ce1b14e main.cpp
--- a/main.cpp	Wed Aug 16 13:51:57 2017 +0000
+++ b/main.cpp	Thu Aug 31 14:08:54 2017 +0000
@@ -3,8 +3,13 @@
 // Read temperature from MAX1363 3-channel ADC
 
 I2C i2c(PB_9 , PB_8);
+DigitalOut Relay(D7);
+Serial pc(SERIAL_TX, SERIAL_RX);
 
-Serial pc(SERIAL_TX, SERIAL_RX);
+char buffer[]={'0','0','0','0','0','\0'};
+char ch;
+double SetTemp=0;
+float x=0;
 
 // address information for the Serenity temperature sensor device
 const int SLAVE_ADDRESS = 0x34 << 1;
@@ -44,8 +49,21 @@
     return temp_k + CONV_K_TO_C;
 }
 
+void callback(){
+if (pc.readable()==1){
+        for (int index=0; index<5; index=index+1){
+            ch=pc.getc();
+            buffer[index]=ch;
+        }
+        SetTemp= atof(buffer);
+return;
+}
+}
+
 int main() {
-    pc.baud(250000);
+    pc.baud(115200);
+    
+    pc.attach(&callback);
 
     // reserve 4 bytes for transfer
     char cmd[4];
@@ -60,7 +78,7 @@
     float values[2] = {0};
 
     while (1) {
-        wait(0.5);
+        wait(0.1);
 
         // clear buffer, only to detect invalid data
         cmd[0] = 0x00;
@@ -81,14 +99,15 @@
                 // handle invalid data
             }
         }
-
+        x=values[1];
+        if (x<SetTemp){
+            Relay=0;
+        }
+        if (x>SetTemp+1){
+            Relay=1;
+        }
         // output temperature data
-        
-        printf("%0.2f\t %0.2f\r\n", values[0], values[1]);
+        printf("%0.2f\t %0.2f\t %0.2f\r\n", SetTemp, values[0], values[1]);
+
     }
 }
-
-
-
-
-