![](/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:
- 4:33f3750fe70a
- Parent:
- 3:51b248042aa0
- Child:
- 6:73866b51e0b7
File content as of revision 4:33f3750fe70a:
#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 DigitalIn AlarmAdjust(p9); 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 time_t rawTime; set.start(); } void timeDisplay(void){ time(&rawTime); t = localtime(&rawTime); HH=t->tm_hour; mm=t->tm_min; //updating local hr and min var //TIME 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 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 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; } }