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

Dependencies:   BMP180 N5110 PowerControl mbed

Revision:
8:9461cda3310b
Parent:
7:32a4756cba1d
Child:
9:098f8e206770
--- a/main.cpp	Thu Apr 30 15:14:53 2015 +0000
+++ b/main.cpp	Thu Apr 30 16:37:52 2015 +0000
@@ -8,6 +8,7 @@
 // Can give better performance due to current limitation from GPIO pin
 
 Ticker timer ; //create a ticker object to read the data from the sensor
+Ticker ticker; //create ticker for RTC
 Timeout timeOut ; //only loops once to show menu
 BusOut leds(LED4,LED3,LED2,LED1); //leds used for error function
 BMP180 bmp180(p28,p27);
@@ -22,6 +23,9 @@
 int timeOutFlag = 0 ;
 int graphFlag = 0 ;
 int currentFlag = 0;
+char rxString[16]; // buffer to store received string
+char bufferTime[14];
+char bufferDate[14];
 float temperature; //temperature has to be a float or graph doesn't work
 float pressure;
 void displayTemperature();
@@ -30,6 +34,10 @@
 void displayTemperatureGraph();
 void displayPressureGraph();
 void error();
+void time();
+void setTime(); // function to set the UNIX time
+void serialISR();
+void interrupt(); //for RTC
 
 void screen() //welcome screen
 {
@@ -42,7 +50,7 @@
 void menu() //main menu screen
 {
     lcd.clear();
-    if (POT>(1.0/2.0)) { //if the potentiometer is pointing to the left (temperature)
+    if (POT>=(3.0/4.0)) { //if the potentiometer is pointing to the left (temperature)
         lcd.printString("Temperature",2,2); //data type label
         lcd.printString(">",76,2); //arrow denoting a different screen can be shown by pointing potentiometer in right direction
         lcd.printString("Graph",0,5);//graph button label
@@ -58,25 +66,48 @@
 
             displayTemperature(); //display current temperature value
         }
-    } else {
+    } else if ((3.0/4.0)>POT && POT>=(1.0/2.0)) {
         lcd.printString("Pressure",18,2);//data type label
         lcd.printString("<",2,2);//arrow denoting a different screen can be shown by pointing potentiometer in left direction
+        lcd.printString(">",76,2); //arrow denoting a different screen can be shown by pointing potentiometer in right direction
         lcd.printString("Graph",0,5);//graph button label
         lcd.printString("Current",42,5);//current button label
         if (graphFlag) { //if the graph button is pressed
             graphFlag = 0; //reset graph flag to 0
             displayPressureGraph();
-        
+
 
         }
+
         if (currentFlag) { // if the current button is pressed
             currentFlag = 0; //reset current flag to 0
             displayPressure();//display current pressure value
         }
+    } else if ((1.0/2.0)>POT && POT>=(1.0/4.0)) {
+        time();
+        lcd.printString("Date",30,0);//date label
+        lcd.printString(">",76,2); //arrow denoting a different screen can be shown by pointing potentiometer in right direction
+        lcd.printString("<",2,2);//arrow denoting a different screen can be shown by pointing potentiometer in left direction
+        lcd.printString(bufferDate,19,2);//date
+    } else {
+        time();
+        lcd.printString("Time",30,0);//time stamp
+        lcd.printString("<",2,2);//arrow denoting a different screen can be shown by pointing potentiometer in left direction
+        lcd.printString(bufferTime,19,2);//time
     }
 }
 
 
+
+
+void time(){
+
+time_t seconds = time(NULL); // get current time
+// format time into a string (time and date)
+        strftime(bufferTime, 14 , "%X", localtime(&seconds));
+        strftime(bufferDate, 14 , "%D", localtime(&seconds));
+}
+
 void timerExpired()
 {
     timerFlag = 1 ;
@@ -240,9 +271,11 @@
     graphButton.rise (&graphButtonPressed);
     currentButton.rise (&currentButtonPressed);
     red.period_us(25);
+    //set_time(1430411800); // initialise time to now
     screen(); //show the welcome screen
 
     while(1) {
+        time();
         if (timeOutFlag ==1 ) {
             menu(); //display menu screen(s)
         }