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.
Fork of SmartRise_MBED by
TimeControl.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 00004 //IO 00005 TextLCD lcd(p27,p28,p23,p24,p25,p26); //RS E d1,d2,d3,d4 00006 DigitalIn HrAdjustUp(p6); 00007 DigitalIn HrAdjustDown(p7); 00008 DigitalIn MinAdjust(p8); //buttons for setting time and alarm 00009 DigitalIn AlarmAdjust2(p9); 00010 00011 DigitalOut arm(p12); 00012 // 1454284799 is the end of Febuary 00013 00014 struct tm* t; 00015 int Ahh,AHH,Amm; 00016 int HH,mm,hh; //HH 24hr || hh 12hr 00017 char d,ad; //am0/pm1 00018 Timer set; 00019 00020 void time_init(void){ //starting time and timers 00021 set.start(); 00022 set_time(1454284799+10); 00023 AHH=12;Amm=0; 00024 } 00025 00026 void timeDisplay(void){ //main time management function and display 00027 time_t rawTime; 00028 time(&rawTime); 00029 t = localtime(&rawTime); 00030 HH=t->tm_hour; mm=t->tm_min; //updating local hr and min var 00031 00032 //TIME format 00033 if(HH>12)hh=HH-12; else hh=HH+0.1; // I don't know why this makes it work but it does 00034 if(HH ==0){hh = HH+12.1;} 00035 //convert 24 to 12 hr 00036 if(HH>=12) d='P'; else d='A'; //update am/pm 00037 //Alarm format 00038 if(AHH>12)Ahh=AHH-12; else Ahh=AHH; //convert 24 to 12 hr 00039 if(AHH>=12) ad='P'; else ad='A'; 00040 00041 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 00042 } 00043 00044 char checkAlarm(void){ 00045 if(HH==AHH&&mm==Amm&&d==ad) return 1; 00046 else return 0; 00047 } 00048 00049 void alarmProg(void){ //Alarm set/adjust function to be called in main, when alarm set switch is enabled 00050 if(set.read()>0.3){ 00051 if(HrAdjustUp==1) {AHH=AHH+1;set.reset();} 00052 if(HrAdjustDown==1) {AHH=AHH-1;set.reset();} 00053 if(MinAdjust==1) {Amm=Amm+1;set.reset();} 00054 if(AHH>23) AHH=0; if(AHH<0) AHH=23; 00055 if(AHH>=12) ad='P'; else ad='A'; 00056 if(Amm>=60) Amm=0; 00057 } 00058 } 00059 00060 void timeProg(void){ 00061 time_t seconds = time(NULL); 00062 if(set.read()>0.3){ 00063 if(HrAdjustUp==1 && AlarmAdjust2 ==1){ // Adjust Day Forward 00064 set_time(seconds+86400); 00065 set.reset(); 00066 } 00067 else if(HrAdjustUp==1){ 00068 set_time(seconds+60*60); 00069 set.reset(); 00070 } 00071 if(HrAdjustDown==1 && AlarmAdjust2 ==1){ // Adjust Day Backward 00072 set_time(seconds- 86400); 00073 set.reset(); 00074 } 00075 else if(HrAdjustDown==1){ 00076 set_time(seconds-60*60); 00077 set.reset(); 00078 } 00079 else if(MinAdjust==1){ 00080 set_time(seconds+60); 00081 set.reset(); 00082 } 00083 } 00084 } 00085
Generated on Thu Jul 14 2022 11:15:41 by
1.7.2
