![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Lab 3 Temp on LCD
Dependencies: C12832 LM75B mbed
Fork of app-board-LM75B by
Diff: main.cpp
- Revision:
- 6:7ad7cd03f029
- Parent:
- 5:608f2bf4d3f7
--- 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); }