Alarm Clock

Dependencies:   TextLCD mbed

Fork of SmartRise_MBED by Austin Sloop

Revision:
4:33f3750fe70a
Parent:
3:51b248042aa0
Child:
6:73866b51e0b7
--- a/TimeControl.cpp	Mon Jan 25 21:08:47 2016 +0000
+++ b/TimeControl.cpp	Tue Jan 26 00:47:00 2016 +0000
@@ -1,8 +1,53 @@
+#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;
+    }
+}
 
 
-
-