Orla Gilson / Mbed 2 deprecated WeatherLogger

Dependencies:   BMP180 N5110 mbed

Revision:
1:1accd82f4281
Parent:
0:2fd314d76f37
Child:
2:6b564e388747
--- a/main.cpp	Thu Apr 30 11:46:15 2015 +0000
+++ b/main.cpp	Thu Apr 30 12:32:57 2015 +0000
@@ -20,31 +20,46 @@
 
 void clearCells();
 
+Ticker timerT;
+Ticker timerP;
+
+int timerTFlag = 0;
+int timerPFlag = 0;
+
+void timerTExpired(){
+    timerTFlag = 1;
+}
+void timerPExpired(){
+    timerPFlag = 1;
+}
+
 void readTemp(){
     while(1){
-        Measurement measurement;
-        clearCells();
-        char buffer1[14];
-        measurement = bmp180.readValues();
-        int length=sprintf(buffer1,"T = %.2f C",measurement.temperature);
-        if (length<=14){
-            lcd.printString(buffer1,10,2);
+        if (timerTFlag){
+            timerTFlag=0;
+            clearCells();
+            char bufferT[14];
+            measurement = bmp180.readValues();
+            int length=sprintf(bufferT,"T = %.2f C",measurement.temperature);
+            if (length<=14){
+                lcd.printString(bufferT,10,2);
+            }
         }
-        wait(2.0);
     }
 }
 
 void readPress(){
     while(1){
-        Measurement measurement;
-        clearCells();
-        char buffer2[14];
-        measurement = bmp180.readValues();
-        int length=sprintf(buffer2,"P = %.2f mb",measurement.pressure);
-        if (length<=14){
-            lcd.printString(buffer2,0,2);
+        if (timerPFlag){
+            timerPFlag=0;
+            clearCells();
+            char bufferP[14];
+            measurement = bmp180.readValues();
+            int length=sprintf(bufferP,"P = %.2f mb",measurement.pressure);
+            if (length<=14){
+                lcd.printString(bufferP,0,2);
+            }
         }
-        wait(2.0);
     }
 }
 
@@ -113,9 +128,11 @@
     lcd.refresh (); //must refresh to write buffer to display
 }
 
-int main()
-{
- lcd.init();
- bmp180.init();
- menu();
+int main(){
+    lcd.init();
+    bmp180.init();
+    timer.attach(&timerTExpired,60);
+    timer.attach(&timerPExpired,1800);
+    Measurement measurement;
+    menu();
 }
\ No newline at end of file