Program to display temperature and pressure readings along with date and time.

Dependencies:   BMP180 N5110 PowerControl mbed

Revision:
2:63ef0a1afcbe
Parent:
1:026d80a2f7a9
Child:
3:075786ca7621
--- a/main.cpp	Wed Apr 29 14:21:02 2015 +0000
+++ b/main.cpp	Wed Apr 29 14:58:40 2015 +0000
@@ -8,15 +8,25 @@
 // Can give better performance due to current limitation from GPIO pin
 
 Ticker timer ; //create a ticker object to read the data from the sensor
-Timeout timeOut ; 
+Timeout timeOut ;
 BMP180 bmp180(p28,p27);
 Serial serial(USBTX,USBRX);
 AnalogIn POT(p20);
+InterruptIn graphButton(p16); //button to select graph
+InterruptIn currentButton(p15); //button to select current
 
 int timerFlag= 0;
 int timeOutFlag = 0 ;
+int graphFlag = 0 ;
+int currentFlag = 0;
 int temperature ;
 float pressure;
+void displayTemperature();
+void displayPressure();
+void recieveData();
+
+
+
 
 
 void screen()
@@ -35,25 +45,63 @@
         lcd.printString(">",76,2);
         lcd.printString("Graph",0,5);
         lcd.printString("Current",42,5);
+        if (graphFlag) {
+            graphFlag = 0;
 
+        }
+        if (currentFlag ==1 ) { // if the current button is pressed
+            currentFlag = 0;
+            while(1) {
+                if (timerFlag ==1) { // if the timer flag is set (Timer every 1.0 second)
+                    timerFlag = 0;
+                    displayTemperature();
+                }
+            } // while loop ends
+        }
     } else {
         lcd.printString("Pressure",18,2);
         lcd.printString("<",2,2);
         lcd.printString("Graph",0,5);
         lcd.printString("Current",42,5);
+        if (graphFlag) {
+            graphFlag = 0;
 
+        }
+        if (currentFlag) { // if the current button is pressed
+            currentFlag = 0;
+            while(1) {
+                if (timerFlag ==1) { // if the timer flag is set (Timer every 1.0 second)
+                    timerFlag = 0;
+                    displayPressure();
+                }
+                wait (0.1);
+            } // while loop ends
+        }
     }
 }
 
-void timerExpired(){
+void timerExpired()
+{
     timerFlag = 1 ;
 }
 
-void timeOutStopped(){
-    
+void timeOutStopped()
+{
+
     timeOutFlag = 1;
-    }
+}
 
+void graphButtonPressed ()
+{
+    graphFlag = 1;
+        serial.printf("graph button pressed ");
+}
+
+void currentButtonPressed ()
+{
+    currentFlag = 1;
+            serial.printf("current button pressed ");
+}
 void recieveData()
 {
 
@@ -69,23 +117,32 @@
 }
 
 
-void displayData()
+void displayTemperature()
 {
-
+    lcd.clear();
+        recieveData();
     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
     // or create formatted strings - ensure they aren't more than 14 characters long
     int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer
     // it is important the format specifier ensures the length will fit in the buffer
+            serial.printf( " L %i",length);
     if (length <= 14)  // if string will fit on display
-        lcd.printString(buffer,0,1);           // display on screen
-    length = sprintf(buffer,"P = %.2f mb",pressure);
-    if (length <= 14)
-        lcd.printString(buffer,0,2);
+        lcd.printString(buffer,0,2);           // display on screen
 
 }
 
+void displayPressure()
+{
+        lcd.clear();
+            recieveData();
+    char buffer1[14];
+    int length1 = sprintf(buffer1,"P = %.2fmb",pressure);
+     serial.printf( " L1 %i",length1);
+    if (length1 <= 14)
+        lcd.printString(buffer1,0,2);
 
+}
 
 
 
@@ -97,22 +154,14 @@
     bmp180.init();
     timer.attach (&timerExpired , 1.0);
     timeOut.attach (&timeOutStopped , 2.0);
+    graphButton.rise (&graphButtonPressed);
+    currentButton.rise (&currentButtonPressed);
     screen();
 
     while(1) {
-        if (timeOutFlag ==1 ){
-            
+        if (timeOutFlag ==1 ) {
             menu();
-            
-            
-            
-//        if (timerFlag ==1){
-//            timerFlag = 0;
-//        lcd.clear();
-//        recieveData();
-//        displayData();
-//        //  menu();
-//        }
-    }
+        }
+                        wait (0.1);
     }
 }