Simple Weather Station. Data Logger and gives primitive weather predictions.

Dependencies:   BMP180 N5110 PowerControl beep mbed

Files at this revision

API Documentation at this revision

Comitter:
el13nsp
Date:
Tue Apr 21 13:28:17 2015 +0000
Parent:
0:de50a430cb9d
Child:
2:a6b66d8dd770
Commit message:
Added Main Ticker

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Apr 21 12:50:18 2015 +0000
+++ b/main.cpp	Tue Apr 21 13:28:17 2015 +0000
@@ -6,7 +6,7 @@
 
 #define USR_POWERDOWN (0x104)
 
-int semihost_powerdown() 
+int semihost_powerdown()
 {
     uint32_t arg;
     return __semihost(USR_POWERDOWN, &arg);
@@ -18,6 +18,16 @@
 
 AnalogIn POT1(p20);
 
+Ticker timer;
+
+int timerFlag=0;
+
+// Interrupt Service Routine
+void timerExpired()
+{
+    timerFlag = 1;
+}
+
 InterruptIn button(p17);
 
 //    VCC,SCE,RST,D/C,MOSI,SCLK,LED
@@ -39,17 +49,18 @@
 }
 
 int main()
-{   
+{
+    timer.attach(&timerExpired,2.0); // Call ISR every 1 second
 
     PHY_PowerDown();
     int result = semihost_powerdown();
-    
+
     button.mode(PullUp);
-    
+
     //for(int x=0; x<84; x++) {
     //    array[x] = 0;
     //}
-    
+
     // initiliase barometer
     bmp180.init();
 
@@ -66,36 +77,47 @@
 
     while(1) {
 
-        char buffer[14];  // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
-        // so can display a string of a maximum 14 characters in length
+
+        lcd.setBrightness(POT1); // put LED backlight on full
+
+
+        if(timerFlag) {
+
+            timerFlag = 0;
 
-        lcd.clear();            // clear display
-        leds = 1;
-        lcd.setBrightness(POT1); // put LED backlight on full
-        
-        // read values (T in Celsius and P in mb) and print over serial port
-        measurement = bmp180.readValues();
+            lcd.clear();            // clear display
+            char buffer[14];  // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
+            // so can display a string of a maximum 14 characters in length
+            leds = 0;
+
+            // read values (T in Celsius and P in mb) and print over serial port
+            measurement = bmp180.readValues();
 
-        int length = sprintf(buffer,"T = %.2f C",measurement.temperature); // print formatted data to buffer
-        // it is important the format specifier ensures the length will fit in the buffer
-        if (length <= 14)  // if string will fit on display
-            lcd.printString(buffer,0,1);           // display on screen
+            int length = sprintf(buffer,"T = %.2f C",measurement.temperature); // print formatted data to buffer
+            // it is important the format specifier ensures the length will fit in the buffer
+            if (length <= 14)  // if string will fit on display
+                lcd.printString(buffer,0,1);           // display on screen
+
+            length = sprintf(buffer,"P = %.2f mb",measurement.pressure);
+            if (length <= 14)
+                lcd.printString(buffer,0,2);
 
-        length = sprintf(buffer,"P = %.2f mb",measurement.pressure);
-        if (length <= 14)
-            lcd.printString(buffer,0,2);
+            // need to refresh display after setting pixels
+            lcd.refresh();
 
-        if(i==84) {
-            for (int n = 0; n < 83; n++) {
-                array[n] = array[n+1];
-                i=83;
+            if(i==84) {
+                for (int n = 0; n < 83; n++) {
+                    array[n] = array[n+1];
+                    i=83;
+                }
             }
+
+            array[i] = measurement.temperature/65;
+            i++;
+
         }
 
-        array[i] = measurement.temperature/65;
-        i++;
-
-        if (buttonFlag) { // if flag is set            
+        if (buttonFlag) { // if flag is set
             //DO SOMETHING HERE
             lcd.clear();            // clear display
             lcd.plotArray(array);
@@ -103,12 +125,11 @@
             wait(5.0);
             buttonFlag = 0; //reset flag
         }
-        // need to refresh display after setting pixels
-        lcd.refresh();
+
 
         // can also check status of pixels using getPixel(x,y)
 
-        wait(1.0);
+        //wait(1.0);
 
     }
 }