Amir Asemanpayeh / Mbed 2 deprecated WeatherStation

Dependencies:   BMP180 N5110 PowerControl mbed

Revision:
5:6952998ab446
Parent:
4:783276521952
Child:
6:03f12eda070d
--- a/main.cpp	Fri Apr 10 03:09:38 2015 +0000
+++ b/main.cpp	Sun Apr 12 08:36:02 2015 +0000
@@ -23,6 +23,7 @@
 int button2Flag = 0 ;
 int button3Flag = 0 ;
 int button4Flag = 0 ;
+int unitFlag = 1 ;
 
 
 
@@ -134,12 +135,30 @@
     measurement = bmp180.readValues();
     // serial.printf("T = %.2f C P = %.2f mb\n",measurement.temperature,measurement.pressure);
 
-    int temperature = measurement.temperature;
-    length = sprintf(bufferT,"T = %0.1d C",temperature); // print formatted data to buffer
+    int temperatureC = measurement.temperature;
+    int temperatureF = (temperatureC*(9/5))+32;
+    
+    if (unitFlag==1 || unitFlag==2 ){
+    length = sprintf(bufferT,"T = %0.1d C",temperatureC); // print formatted data to buffer
+    // it is important the format specifier ensures the length will fit in the buffer
+    }
+    if (unitFlag==3 || unitFlag==4 ){
+    length = sprintf(bufferT,"T = %0.1d F",temperatureF); // print formatted data to buffer
     // it is important the format specifier ensures the length will fit in the buffer
+    }
 
-    float pressure = measurement.pressure;  // same idea with floats
-    length = sprintf(bufferP,"P = %.2f mb",pressure);
+    float pressureMB = measurement.pressure;  // same idea with floats
+    float pressureATM = pressureMB*0.0009869;
+    
+    
+    if (unitFlag==1 || unitFlag==3 ){
+    length = sprintf(bufferP,"P = %.2f mb",pressureMB); // print formatted data to buffer
+    // it is important the format specifier ensures the length will fit in the buffer
+    }
+    if (unitFlag==2 || unitFlag==4 ){
+    length = sprintf(bufferP,"P = %.2f atm",pressureATM); // print formatted data to buffer
+    // it is important the format specifier ensures the length will fit in the buffer
+    }
 
 
 }
@@ -201,29 +220,110 @@
 
 }
 
+
+
+
+void unitsSetting()
+{
+    choice = 1;
+
+    while (1) {
+
+
+
+        if (choice < 1) {
+            choice = 4;
+        }
+        if (choice > 4) {
+            choice = 1;
+        }
+
+
+
+        switch (choice) {
+            case 1:
+
+                lcd.clear();
+                lcd.printString(bufferTime,48,0);
+                lcd.printString("Units : ",0,2);
+                lcd.printString("C/mb",0,3);
+                lcd.printString("Back      Save",0,5);
+
+                if (button4Flag) {
+                    button4Flag=0;
+                    unitFlag=1;
+                }
+
+
+                break;
+            case 2:
+                lcd.clear();
+                lcd.printString(bufferTime,48,0);
+                lcd.printString("Units : ",0,2);
+                lcd.printString("C/atm",0,3);
+                lcd.printString("Back      Save",0,5);
+                if (button4Flag) {
+                    button4Flag=0;
+                    unitFlag=2;
+                }
+                break;
+            case 3:
+                lcd.clear();
+                lcd.printString(bufferTime,48,0);
+                lcd.printString("Units : ",0,2);
+                lcd.printString("F/mb",0,3);
+                lcd.printString("Back      Save",0,5);
+                if (button4Flag) {
+                    button4Flag = 0;
+                    unitFlag=3;
+                }
+                break;
+            case 4:
+                lcd.clear();
+                lcd.printString(bufferTime,48,0);
+                lcd.printString("Units : ",0,2);
+                lcd.printString("F/atm",0,3);
+                lcd.printString("Back      Save",0,5);
+                if (button4Flag) {
+                    button4Flag=0;
+                    unitFlag=4;
+                }
+                break;
+            default:
+                break;
+
+        }
+        wait (0.1);
+        if (button3Flag) {
+            button3Flag=0;
+            break;
+        }
+    }
+}
+
+
+
+
+
 void brightnessSetting ()
 {
     lcd.clear();
     while(1) {
-     lcd.clear();
-     lcd.refresh();   
-        if (choice << 1) {
-        choice = 6 ;
-    }
-        if (choice >> 6)
-        {
+        lcd.clear();
+        lcd.refresh();
+        if (choice < 1) {
+            choice = 6 ;
+        }
+        if (choice > 6) {
             choice = 1;
-    }
-        
-        float brightness=choice/6;
-        lcd.setBrightness(brightness);
-        
-        
-        int w = choice*10 ;
-        for (int x = 0; x < WIDTH ; x+=10) {
-            // x0,y0,x1,y1,type 0-white,1-black,2-dotted
-            lcd.drawLine(10,24,w,24,1);
         }
+
+
+        if (button4Flag) {
+            button4Flag=0;
+            lcd.setBrightness(choice/10);
+        }
+
         if (button3Flag) {
             button3Flag=0;
             break;
@@ -254,7 +354,6 @@
         int h = sprintf (Hour, "Hour : %d", hour);//convert integer to buffer str
         int mi = sprintf (Min, "Min : %d", min);//convert integer to buffer str
 
-        wait(1);
 
         switch (choice) {
             case 1:
@@ -372,9 +471,9 @@
                 }
                 break;
             default:
-                leds = 15;
                 break;
         }
+        wait (0.1);
     }
 exit_loop:
     ;
@@ -424,7 +523,12 @@
                 lcd.printString("Power Saver",0,4);
                 lcd.printString("Log Interval",0,5);
                 lcd.drawCircle(5,20,3,1);  // x,y,radius,black fill
-// rest of code here
+
+                if (button4Flag) {
+                    button4Flag=0;
+                    unitsSetting();
+                }
+
                 break;
             case 3:
                 lcd.clear();
@@ -476,11 +580,12 @@
             button3Flag=0;
             break;
         }
+        wait (0.1);
     }
 }
 
 
-void startMenu()  //The menu displayed at the beginning
+void startMenu()   //The menu displayed at the beginning
 {
 
     switch (choice) {