Lab 3 Temp on LCD

Dependencies:   C12832 LM75B mbed

Fork of app-board-LM75B by Chris Styles

Files at this revision

API Documentation at this revision

Comitter:
jaredwil
Date:
Tue Mar 03 22:54:16 2015 +0000
Parent:
5:608f2bf4d3f7
Commit message:
Lab3_temp

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 608f2bf4d3f7 -r 7ad7cd03f029 main.cpp
--- a/main.cpp	Thu Feb 06 14:05:51 2014 +0000
+++ b/main.cpp	Tue Mar 03 22:54:16 2015 +0000
@@ -7,17 +7,40 @@
 LM75B sensor(p28,p27);
 Serial pc(USBTX,USBRX);
 
+void pMesg(char * mesg, float temp)
+{
+            lcd.locate(0,3);
+            lcd.printf("Temp = %.3f\n",temp);
+            lcd.locate(0,15);
+            lcd.printf("%s",mesg);
+            wait(2);
+            lcd.cls();
+            lcd.locate(0,3);
+            lcd.printf("Temp = %.3f\n",temp);
+}
+
 int main ()
 {
 
+    float cur_temp, prev_temp;
     //Try to open the LM75B
     if (sensor.open()) {
         printf("Device detected!\n");
-
+    
+    lcd.cls();
+    cur_temp = (float)sensor;
+    prev_temp = cur_temp;
+    pMesg("Normal",prev_temp);
+    
         while (1) {
-            lcd.cls();
-            lcd.locate(0,3);
-            lcd.printf("Temp = %.3f\n", (float)sensor);
+            cur_temp = (float)sensor;
+            if(cur_temp >= prev_temp +2.0) {
+                pMesg("Higher",cur_temp);
+                prev_temp = cur_temp;
+            } else if(cur_temp <= prev_temp - 2.0) {
+                pMesg("Lower",cur_temp);
+                prev_temp = cur_temp;
+            }         
             wait(1.0);
         }