![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Alarm Clock
Fork of SmartRise_MBED by
TimeControl.cpp
- Committer:
- asloop18
- Date:
- 2016-01-26
- Revision:
- 7:5412a6d7ef6d
- Parent:
- 6:73866b51e0b7
- Child:
- 9:63098da649d1
File content as of revision 7:5412a6d7ef6d:
#include "mbed.h" #include "TextLCD.h" //IO TextLCD lcd(p27,p28,p23,p24,p25,p26); //RS E d1,d2,d3,d4 DigitalIn HrAdjustUp(p6); DigitalIn HrAdjustDown(p7); DigitalIn MinAdjust(p8); //buttons for setting time and alarm DigitalOut arm(p12); struct tm* t; int Ahh,AHH,Amm; int HH,mm,hh; //HH 24hr || hh 12hr char d,ad; //am0/pm1 Timer set; void time_init(void){ //starting time and timers set.start(); AHH=12;Amm=0; } void timeDisplay(void){ //main time management function and display time_t rawTime; time(&rawTime); t = localtime(&rawTime); 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) d='P'; else d='A'; //update am/pm //Alarm format if(AHH>12)Ahh=AHH-12; else Ahh=AHH+1; //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 } char checkAlarm(void){ if(HH==AHH&&mm==Amm) return 1; else return 0; } void alarmProg(void){ //Alarm set/adjust function to be called in main, when alarm set switch is enabled if(set.read()>0.3){ if(HrAdjustUp==1) {AHH=AHH+1;set.reset();} if(HrAdjustDown==1) {AHH=AHH-1;set.reset();} if(MinAdjust==1) {Amm=Amm+1;set.reset();} if(AHH>23) AHH=0; if(AHH<0) AHH=23; if(AHH>=12) ad='P'; else ad='A'; if(Amm>=60) Amm=0; } } void timeProg(void){ time_t seconds = time(NULL); if(set.read()>0.3){ if(HrAdjustUp==1){ set_time(seconds+60*60); set.reset(); } if(HrAdjustDown==1){ set_time(seconds-60*60); set.reset(); } if(MinAdjust==1){ set_time(seconds+60); set.reset(); } } }