Whitworth-EN173-2016
/
SmartRise_MBED
Alarm Clock
Fork of SmartRise_MBED by
TimeControl.cpp@4:33f3750fe70a, 2016-01-26 (annotated)
- Committer:
- asloop18
- Date:
- Tue Jan 26 00:47:00 2016 +0000
- Revision:
- 4:33f3750fe70a
- Parent:
- 3:51b248042aa0
- Child:
- 6:73866b51e0b7
Time functions move in progress to CPP
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
asloop18 | 4:33f3750fe70a | 1 | #include "mbed.h" |
asloop18 | 4:33f3750fe70a | 2 | #include "TextLCD.h" |
asloop18 | 3:51b248042aa0 | 3 | |
asloop18 | 4:33f3750fe70a | 4 | //IO |
asloop18 | 4:33f3750fe70a | 5 | TextLCD lcd(p27,p28,p23,p24,p25,p26); //RS E d1,d2,d3,d4 |
asloop18 | 4:33f3750fe70a | 6 | DigitalIn HrAdjustUp(p6); |
asloop18 | 4:33f3750fe70a | 7 | DigitalIn HrAdjustDown(p7); |
asloop18 | 4:33f3750fe70a | 8 | DigitalIn MinAdjust(p8); //buttons for setting time and alarm |
asloop18 | 4:33f3750fe70a | 9 | DigitalIn AlarmAdjust(p9); |
asloop18 | 4:33f3750fe70a | 10 | DigitalOut arm(p12); |
asloop18 | 3:51b248042aa0 | 11 | |
asloop18 | 4:33f3750fe70a | 12 | struct tm* t; |
asloop18 | 4:33f3750fe70a | 13 | int Ahh,AHH,Amm; |
asloop18 | 4:33f3750fe70a | 14 | int HH,mm,hh; //HH 24hr || hh 12hr |
asloop18 | 4:33f3750fe70a | 15 | char d,ad; //am0/pm1 |
asloop18 | 4:33f3750fe70a | 16 | Timer set; |
asloop18 | 4:33f3750fe70a | 17 | |
asloop18 | 4:33f3750fe70a | 18 | void time_init(void){ //starting time and timers |
asloop18 | 4:33f3750fe70a | 19 | time_t rawTime; |
asloop18 | 4:33f3750fe70a | 20 | set.start(); |
asloop18 | 4:33f3750fe70a | 21 | |
asloop18 | 4:33f3750fe70a | 22 | } |
asloop18 | 4:33f3750fe70a | 23 | |
asloop18 | 4:33f3750fe70a | 24 | void timeDisplay(void){ |
asloop18 | 4:33f3750fe70a | 25 | time(&rawTime); |
asloop18 | 4:33f3750fe70a | 26 | t = localtime(&rawTime); |
asloop18 | 4:33f3750fe70a | 27 | HH=t->tm_hour; mm=t->tm_min; //updating local hr and min var |
asloop18 | 4:33f3750fe70a | 28 | |
asloop18 | 4:33f3750fe70a | 29 | //TIME |
asloop18 | 4:33f3750fe70a | 30 | if(HH>12)hh=HH-12; else hh=HH+1; //convert 24 to 12 hr |
asloop18 | 4:33f3750fe70a | 31 | if(HH>=12) d='P'; else d='A'; //update am/pm |
asloop18 | 4:33f3750fe70a | 32 | //Alarm |
asloop18 | 4:33f3750fe70a | 33 | if(AHH>12)Ahh=AHH-12; else Ahh=AHH+1; //convert 24 to 12 hr |
asloop18 | 4:33f3750fe70a | 34 | if(AHH>=12) ad='P'; else ad='A'; |
asloop18 | 4:33f3750fe70a | 35 | |
asloop18 | 4:33f3750fe70a | 36 | |
asloop18 | 4:33f3750fe70a | 37 | 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 |
asloop18 | 4:33f3750fe70a | 38 | |
asloop18 | 4:33f3750fe70a | 39 | |
asloop18 | 3:51b248042aa0 | 40 | |
asloop18 | 3:51b248042aa0 | 41 | |
asloop18 | 4:33f3750fe70a | 42 | void alarmProg(void){ //Alarm set/adjust function to be called in main, when alarm set switch is enabled |
asloop18 | 4:33f3750fe70a | 43 | if(set.read()>0.3){ |
asloop18 | 4:33f3750fe70a | 44 | if(HrAdjustUp==1) {AHH=AHH+1;set.reset();} |
asloop18 | 4:33f3750fe70a | 45 | if(HrAdjustDown==1) {AHH=AHH-1;set.reset();} |
asloop18 | 4:33f3750fe70a | 46 | if(MinAdjust==1) {Amm=Amm+1;set.reset();} |
asloop18 | 4:33f3750fe70a | 47 | if(AHH>23) AHH=0; if(AHH<0) AHH=23; |
asloop18 | 4:33f3750fe70a | 48 | if(AHH>=12) ad='P'; else ad='A'; |
asloop18 | 4:33f3750fe70a | 49 | if(Amm>=60) Amm=0; |
asloop18 | 4:33f3750fe70a | 50 | } |
asloop18 | 4:33f3750fe70a | 51 | } |
asloop18 | 3:51b248042aa0 | 52 | |
asloop18 | 3:51b248042aa0 | 53 |