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

Dependencies:   BMP180 N5110 PowerControl mbed

Revision:
4:f4154181d941
Parent:
3:075786ca7621
Child:
5:fb18fa86ebc3
--- a/main.cpp	Wed Apr 29 15:33:46 2015 +0000
+++ b/main.cpp	Wed Apr 29 16:08:18 2015 +0000
@@ -48,8 +48,9 @@
         lcd.printString("Current",42,5);//current button label
         if (graphFlag) { //if the graph button is pressed
             graphFlag = 0; //reset graph flag to 0
-                    lcd.printString("Menu",0,5); //menu button label
-                    lcd.printString("Current",42,5);//current button label
+            displayTemperatureGraph();
+            // lcd.printString("Menu",0,5); //menu button label
+            // lcd.printString("Current",42,5);//current button label
 
         }
         if (currentFlag ==1 ) { // if the current button is pressed
@@ -70,8 +71,9 @@
         lcd.printString("Current",42,5);//current button label
         if (graphFlag) { //if the graph button is pressed
             graphFlag = 0; //reset graph flag to 0
-            lcd.printString("Menu",0,5);//menu button label
-            lcd.printString("Current",42,5);//current button label
+            displayPressureGraph();
+            //lcd.printString("Menu",0,5);//menu button label
+            //lcd.printString("Current",42,5);//current button label
 
         }
         if (currentFlag) { // if the current button is pressed
@@ -103,13 +105,13 @@
 void graphButtonPressed ()
 {
     graphFlag = 1;
-        serial.printf("graph button pressed "); //used for debugging
+    serial.printf("graph button pressed "); //used for debugging
 }
 
 void currentButtonPressed ()
 {
     currentFlag = 1;
-            serial.printf("current button pressed "); //used for debugging
+    serial.printf("current button pressed "); //used for debugging
 }
 void receiveData() //function to receive data from BMP
 {
@@ -129,13 +131,13 @@
 void displayTemperature() //function to display formatted temperature
 {
     lcd.clear(); //clear screen
-        receiveData(); //get data from function
+    receiveData(); //get data from function
     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); //used for debugging
+    serial.printf( " L %i",length); //used for debugging
     if (length <= 14)  // if string will fit on display
         lcd.printString(buffer,0,2);           // display on screen
 
@@ -143,20 +145,53 @@
 
 void displayPressure() //function to display formatted pressure
 {
-        lcd.clear(); //clear screen
-            receiveData(); //get data from function
+    lcd.clear(); //clear screen
+    receiveData(); //get data from function
     char buffer1[14]; //same as temperature
     int length1 = sprintf(buffer1,"P = %.2fmb",pressure); // print formatted data to buffer1
-     serial.printf( " L1 %i",length1); //used for debugging
+    serial.printf( " L1 %i",length1); //used for debugging
     if (length1 <= 14) // if string will fit on display
         lcd.printString(buffer1,0,2); // display on screen
 
 }
 
-void displayTemperatureGraph() { //function to display temperature graph ober the last hour
+void displayTemperatureGraph()   //function to display temperature graph ober the last hour
+{
+
+    float temperatureArray[84];
+    int j=0;
+    while(1) {
+        lcd.clear();
+        lcd.printString("Menu",0,5);//menu button label
+        lcd.printString("Current",42,5);//current button label
+        receiveData();
+        temperatureArray[j] = temperature;
+        j++;
+        lcd.plotArray(temperatureArray);
+        if (j>83) {
+        memset (temperatureArray,0, sizeof(temperatureArray));
+            j = 0;
+        }
+        wait(0.1);
+    }
 }
 
-void displayPressureGraph() { //function to display pressure graph over the last day
+void displayPressureGraph()   //function to display pressure graph over the last day
+{
+
+    float pressureArray[84];
+    int j=0;
+    while(1) {
+        lcd.clear();
+        receiveData();
+        pressureArray[j] = pressure/1100;
+        j++;
+        lcd.plotArray(pressureArray);
+        if (j>83) {
+            j = 0;
+        }
+        wait(1.0);
+    }
 }
 
 
@@ -174,6 +209,6 @@
         if (timeOutFlag ==1 ) {
             menu(); //display menu screen(s)
         }
-                        wait (0.1); //necessary wait so screen is clear and easy to read
+        wait (0.1); //necessary wait so screen is clear and easy to read
     }
 }