Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BMP180 N5110 PowerControl mbed
Diff: main.cpp
- Revision:
- 1:e60b9f116d38
- Parent:
- 0:d78ac68077c6
- Child:
- 2:1d7ef0f49b35
--- a/main.cpp Wed Apr 08 14:11:09 2015 +0000
+++ b/main.cpp Thu Apr 09 18:59:44 2015 +0000
@@ -6,20 +6,25 @@
BMP180 bmp180(p28,p27); // SDA, SCL
N5110 lcd(p7,p8,p9,p10,p11,p13,p26);
+BusOut leds(LED4,LED3,LED2,LED1);
Serial serial(USBTX,USBRX);
+InterruptIn button1(p16);
+InterruptIn button2(p17);
+
+
Ticker timer; //Create ticker object for temperature and pressure readings
Ticker timer1; //Create ticker object for real time clock
-
-void serialISR(); // ISR that is called when serial data is received
-void setTime(); // function to set the UNIX time
-
int setTimeFlag = 0; // flag for real time clock ISR
int timerFlag = 0; // Flag for tempesrature pressure reading ISR
+int button1Flag = 0;
+int button2Flag = 0 ;
+int choice=1 ;
int length;
+
char bufferTime[14]; // buffer to store time
char bufferDate[14]; //buffer to store date
char bufferT[14];
@@ -29,11 +34,30 @@
+void button1Pressed() //ISR to subtract 1 from the value of choice when the first button is pressed
+{
+ choice --;
+ if (choice == 0) {
+ choice = 5 ;
+ }
+
+}
+
+
+
+void button2Pressed() //ISR to add 1 to the value of the choice when the second button is pressed
+{
+ choice ++;
+ if (choice == 6) {
+ choice = 1 ;
+ }
+
+}
void timer1Expired()
{
-// set flagb
+// set flag
setTimeFlag = 1;
}
@@ -47,7 +71,7 @@
setTimeFlag=0;
time_t seconds = time(NULL); // get current time
// format time into a string (time and date)
- strftime(bufferTime, 14 , "%X", localtime(&seconds));
+ strftime(bufferTime, 14 , "%I:%M", localtime(&seconds));
strftime(bufferDate, 14 , "%d/%m/%y", localtime(&seconds));
}
}
@@ -55,14 +79,14 @@
-void timerExpired()
+void timerExpired() // ISR which sets the timer flag (flag used to display the buffers on LCD)
{
timerFlag=1;
}
-void readData()
+void readData() //Imports the data and saves them to the bufferss
{
Measurement measurement; // measurement structure declared in BMP180 class
@@ -82,7 +106,9 @@
}
-void displayData()
+
+
+void displayData() //Prints the buffers on the LCD
{
if (length <= 14) { // if string will fit on display
lcd.printString(bufferT,0,1); // display on screen
@@ -93,7 +119,9 @@
}
-void updateData()
+
+
+void updateData() //
{
if (timerFlag) {
timerFlag=0;
@@ -104,6 +132,74 @@
}
+void startMenu() //The menu displayed at the beginning
+{
+
+ switch (choice) {
+ case 1:
+
+ lcd.clear();
+ lcd.printString(bufferTime,48,0);
+ lcd.printString("Live Data",20,1);
+ lcd.printString("Saved Data",0,2);
+ lcd.printString("Forecast",0,3);
+ lcd.printString("Alarms",0,4);
+ lcd.printString("Settings",0,5);
+ lcd.drawCircle(5,12,3,1); // x,y,radius,black fill
+
+// rest of code here
+ break;
+ case 2:
+ lcd.clear();
+ lcd.printString(bufferTime,48,0);
+ lcd.printString("Live Data",0,1);
+ lcd.printString("Saved Data",20,2);
+ lcd.printString("Forecast",0,3);
+ lcd.printString("Alarms",0,4);
+ lcd.printString("Settings",0,5);
+ lcd.drawCircle(5,20,3,1); // x,y,radius,black fill
+// rest of code here
+ break;
+ case 3:
+ lcd.clear();
+ lcd.printString(bufferTime,48,0);
+ lcd.printString("Live Data",0,1);
+ lcd.printString("Saved Data",0,2);
+ lcd.printString("Forecast",20,3);
+ lcd.printString("Alarms",0,4);
+ lcd.printString("Settings",0,5);
+ lcd.drawCircle(5,28,3,1); // x,y,radius,black fill
+// rest of code here
+ break;
+ case 4:
+ lcd.clear();
+ lcd.printString(bufferTime,48,0);
+ lcd.printString("Live Data",0,1);
+ lcd.printString("Saved Data",0,2);
+ lcd.printString("Forecast",0,3);
+ lcd.printString("Alarms",20,4);
+ lcd.printString("Settings",0,5);
+ lcd.drawCircle(5,36,3,1); // x,y,radius,black fill
+ break;
+ case 5:
+
+ lcd.clear();
+ lcd.printString(bufferTime,48,0);
+ lcd.printString("Live Data",0,1);
+ lcd.printString("Saved Data",0,2);
+ lcd.printString("Forecast",0,3);
+ lcd.printString("Alarms",0,4);
+ lcd.printString("Settings",20,5);
+ lcd.drawCircle(5,44,3,1); // x,y,radius,black fill
+ break;
+ default:
+ leds = 15;
+ break;
+ }
+}
+
+
+
int main()
{
@@ -112,11 +208,16 @@
lcd.init();
timer.attach(&timerExpired,1.0);
timer1.attach(&timer1Expired,1.0);
+ button1.rise(&button1Pressed); // call ISR on rising edge (button1pressed)
+ button2.rise(&button2Pressed); // call ISR on rising edge (button2pressed)
+
set_time(0); // initialise time to 1st January 1970///// This is where we should set our time
while(1) {
setTime();
- updateData();
+ //updateData();
+ startMenu();
+ wait (0.3);
}
}