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:
- 3:8a559b949470
- Parent:
- 2:1d7ef0f49b35
- Child:
- 4:783276521952
--- a/main.cpp Thu Apr 09 20:40:25 2015 +0000
+++ b/main.cpp Thu Apr 09 22:09:09 2015 +0000
@@ -15,7 +15,6 @@
Ticker timer; //Create ticker object for temperature and pressure readings
-Ticker timer1; //Create ticker object for real time clock
int setTimeFlag = 0; // flag for real time clock ISR
@@ -30,7 +29,7 @@
int choice=1 ;
int length;
-
+char rxString[16]; //buffer to store recieved string from serial
char bufferTime[14]; // buffer to store time
char bufferDate[14]; //buffer to store date
char bufferT[14];
@@ -40,6 +39,7 @@
+
void button1Pressed() //ISR to subtract 1 from the value of choice when the first button is pressed
{
choice --;
@@ -78,30 +78,41 @@
-void timer1Expired()
+void serialISR()
{
-// set flag
- setTimeFlag = 1;
+ //reads rx string into buffer when a serial interrupt occurs
+ serial.gets(rxString,16);
+ //set flag
+ setTimeFlag=1;
+}
+
+
+
+void setTime() // sets the time every second
+{
+//print time for debugging
+serial.printf("set_time -%s ",rxString);
+//atoi() converts a string to an integer
+int time = atoi(rxString);
+//update the time
+set_time(time);
}
-
-void setTime() // sets the time every second
+void updateTime()
{
-
- if (setTimeFlag) {
- setTimeFlag=0;
- time_t seconds = time(NULL); // get current time
+ time_t seconds = time(NULL); // get current time
// format time into a string (time and date)
strftime(bufferTime, 14 , "%I:%M", localtime(&seconds));
strftime(bufferDate, 14 , "%d/%m/%y", localtime(&seconds));
+
+ if (setTimeFlag) {
+ setTimeFlag=0;
}
}
-
-
void timerExpired() // ISR which sets the timer flag (flag used to display the buffers on LCD)
{
timerFlag=1;
@@ -156,6 +167,82 @@
+void timeDate()
+{
+
+
+choice = 1 ;
+while (1){
+
+ switch (choice) {
+ case 1:
+
+ lcd.clear();
+ lcd.printString("Minute :",20,0);
+ lcd.printString("Hour :",0,1);
+ lcd.printString("Day :",0,2);
+ lcd.printString("Month :",0,3);
+ lcd.printString("Year :",0,4);
+ 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
+ if (button4Flag) {
+ button4Flag=0;
+ }
+ break;
+ default:
+ leds = 15;
+ break;
+ }
+
+ }
+}
+
+
+
void settingsMenu()
{
@@ -163,7 +250,7 @@
choice = 1 ;
while(1) {
- setTime();
+ updateTime();
switch (choice) {
case 1:
@@ -316,7 +403,7 @@
bmp180.init();
lcd.init();
timer.attach(&timerExpired,1.0);
- timer1.attach(&timer1Expired,1.0);
+ serial.attach(&serialISR);
button1.rise(&button1Pressed); // call ISR on rising edge (button1pressed)
button2.rise(&button2Pressed); // call ISR on rising edge (button2pressed)
button3.rise(&button3Pressed);
@@ -325,7 +412,7 @@
set_time(0); // initialise time to 1st January 1970///// This is where we should set our time
while(1) {
- setTime();
+ updateTime();
//updateData();
startMenu();
wait (0.5);