alarm with reset
Dependencies: RTC-DS1307 mbed
main.cpp@1:bd4c4722c453, 2017-05-23 (annotated)
- Committer:
- Owenmatthewmcgowan
- Date:
- Tue May 23 14:14:49 2017 +0000
- Revision:
- 1:bd4c4722c453
- Parent:
- 0:72a2484d36f7
156
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Owenmatthewmcgowan | 0:72a2484d36f7 | 1 | #include "mbed.h" |
Owenmatthewmcgowan | 0:72a2484d36f7 | 2 | #include "Rtc_Ds1307.h" |
Owenmatthewmcgowan | 1:bd4c4722c453 | 3 | Rtc_Ds1307 rtc(A4,A5); |
Owenmatthewmcgowan | 1:bd4c4722c453 | 4 | DigitalOut buzzer(PTC9); |
Owenmatthewmcgowan | 1:bd4c4722c453 | 5 | DigitalOut gnd(PTC11); |
Owenmatthewmcgowan | 0:72a2484d36f7 | 6 | |
Owenmatthewmcgowan | 0:72a2484d36f7 | 7 | Rtc_Ds1307::Time_rtc tm = (); |
Owenmatthewmcgowan | 0:72a2484d36f7 | 8 | Rtc_Ds1307::Time_rtc A_tm = (); |
Owenmatthewmcgowan | 0:72a2484d36f7 | 9 | |
Owenmatthewmcgowan | 1:bd4c4722c453 | 10 | bool f_reset ; |
Owenmatthewmcgowan | 1:bd4c4722c453 | 11 | bool f_alarm ; |
Owenmatthewmcgowan | 1:bd4c4722c453 | 12 | void setalarm(int min, int hour); |
Owenmatthewmcgowan | 1:bd4c4722c453 | 13 | void checktime(int min, int hour); |
Owenmatthewmcgowan | 0:72a2484d36f7 | 14 | |
Owenmatthewmcgowan | 0:72a2484d36f7 | 15 | void setalarm(int min, int hour){ |
Owenmatthewmcgowan | 1:bd4c4722c453 | 16 | &A_tm.min = min |
Owenmatthewmcgowan | 1:bd4c4722c453 | 17 | &A_tm.hour = hour |
Owenmatthewmcgowan | 1:bd4c4722c453 | 18 | ; } |
Owenmatthewmcgowan | 0:72a2484d36f7 | 19 | |
Owenmatthewmcgowan | 0:72a2484d36f7 | 20 | |
Owenmatthewmcgowan | 1:bd4c4722c453 | 21 | void alarmoff (){ |
Owenmatthewmcgowan | 1:bd4c4722c453 | 22 | gnd=0; |
Owenmatthewmcgowan | 0:72a2484d36f7 | 23 | // buzzer.period(0); |
Owenmatthewmcgowan | 0:72a2484d36f7 | 24 | // buzzer.write(0); |
Owenmatthewmcgowan | 1:bd4c4722c453 | 25 | buzzer = 0; |
Owenmatthewmcgowan | 1:bd4c4722c453 | 26 | } |
Owenmatthewmcgowan | 0:72a2484d36f7 | 27 | |
Owenmatthewmcgowan | 0:72a2484d36f7 | 28 | |
Owenmatthewmcgowan | 0:72a2484d36f7 | 29 | void alarmon (){ |
Owenmatthewmcgowan | 0:72a2484d36f7 | 30 | gnd = 0; |
Owenmatthewmcgowan | 1:bd4c4722c453 | 31 | // buzzer.period(0.1); |
Owenmatthewmcgowan | 1:bd4c4722c453 | 32 | // buzzer.write(.75); |
Owenmatthewmcgowan | 1:bd4c4722c453 | 33 | buzzer = 1 ; |
Owenmatthewmcgowan | 1:bd4c4722c453 | 34 | |
Owenmatthewmcgowan | 0:72a2484d36f7 | 35 | } |
Owenmatthewmcgowan | 0:72a2484d36f7 | 36 | |
Owenmatthewmcgowan | 0:72a2484d36f7 | 37 | void checktime(int min, int hour){ |
Owenmatthewmcgowan | 0:72a2484d36f7 | 38 | if (&A_tm.hour == &tm.hour) && ( &A_tm.min == &tm.min ){ |
Owenmatthewmcgowan | 0:72a2484d36f7 | 39 | if (f_alarm) { |
Owenmatthewmcgowan | 0:72a2484d36f7 | 40 | alarm_on() |
Owenmatthewmcgowan | 0:72a2484d36f7 | 41 | } |
Owenmatthewmcgowan | 0:72a2484d36f7 | 42 | } |
Owenmatthewmcgowan | 1:bd4c4722c453 | 43 | ;} |
Owenmatthewmcgowan | 0:72a2484d36f7 | 44 | |
Owenmatthewmcgowan | 0:72a2484d36f7 | 45 | |
Owenmatthewmcgowan | 1:bd4c4722c453 | 46 | void checkreset() { |
Owenmatthewmcgowan | 1:bd4c4722c453 | 47 | if (f_reset) { |
Owenmatthewmcgowan | 1:bd4c4722c453 | 48 | alarm_off() |
Owenmatthewmcgowan | 1:bd4c4722c453 | 49 | } |
Owenmatthewmcgowan | 1:bd4c4722c453 | 50 | } |