Whitworth-EN173-2016
/
SmartRise_MBED
Alarm Clock
Fork of SmartRise_MBED by
Diff: TimeControl.cpp
- Revision:
- 12:f42b74f76630
- Parent:
- 9:63098da649d1
- Child:
- 13:2ba69c3dc08a
diff -r be164273b969 -r f42b74f76630 TimeControl.cpp --- a/TimeControl.cpp Wed Jan 27 02:03:43 2016 +0000 +++ b/TimeControl.cpp Wed Jan 27 04:46:00 2016 +0000 @@ -6,8 +6,10 @@ DigitalIn HrAdjustUp(p6); DigitalIn HrAdjustDown(p7); DigitalIn MinAdjust(p8); //buttons for setting time and alarm +DigitalIn AlarmAdjust2(p9); DigitalOut arm(p12); +// 1454284799 is the end of Febuary struct tm* t; int Ahh,AHH,Amm; @@ -17,6 +19,7 @@ void time_init(void){ //starting time and timers set.start(); + set_time(1454284799); AHH=12;Amm=0; } @@ -27,13 +30,15 @@ HH=t->tm_hour; mm=t->tm_min; //updating local hr and min var //TIME format - if(HH>12)hh=HH-12; else hh=HH+1; //convert 24 to 12 hr + if(HH>12)hh=HH-12; else hh=HH+0.1; // I don't know why this makes it work but it does + if(HH ==0){hh = HH+12.1;} + //convert 24 to 12 hr if(HH>=12) d='P'; else d='A'; //update am/pm //Alarm format if(AHH>12)Ahh=AHH-12; else Ahh=AHH; //convert 24 to 12 hr if(AHH>=12) ad='P'; else ad='A'; - lcd.printf(" %2d/%.2d %2d:%.2d%cM Alarm-%2I:%.2I%cM " , t->tm_mon+1,t->tm_mday,hh,t->tm_min,d,Ahh,Amm,ad); //Print date(month/day), time + lcd.printf(" %2d/%.2d %2d:%.2d%cM Alarm -> %2I:%.2I%cM" , t->tm_mon+1,t->tm_mday,hh,t->tm_min,d,Ahh,Amm,ad); //Print date(month/day), time } char checkAlarm(void){ @@ -55,15 +60,23 @@ void timeProg(void){ time_t seconds = time(NULL); if(set.read()>0.3){ - if(HrAdjustUp==1){ + if(HrAdjustUp==1 && AlarmAdjust2 ==1){ // Adjust Day Forward + set_time(seconds+86400); + set.reset(); + } + else if(HrAdjustUp==1){ set_time(seconds+60*60); set.reset(); } - if(HrAdjustDown==1){ + if(HrAdjustDown==1 && AlarmAdjust2 ==1){ // Adjust Day Backward + set_time(seconds- 86400); + set.reset(); + } + else if(HrAdjustDown==1){ set_time(seconds-60*60); set.reset(); } - if(MinAdjust==1){ + else if(MinAdjust==1){ set_time(seconds+60); set.reset(); }