1
1
/*
2
- Author: Adam Garbo and Nathan Seidle
2
+ Author: rserranosmith, Adam Garbo, and Nathan Seidle
3
3
Created: June 3rdrd, 2020
4
4
5
5
This example demonstrates how to read and set rolling RTC alarms. Each time
@@ -47,7 +47,10 @@ void setup()
47
47
6: Alarm match every minute (hundredths, seconds)
48
48
7: Alarm match every second (hundredths)
49
49
*/
50
- rtc.setAlarmMode (6 ); // Set the RTC alarm to match on minutes rollover
50
+ rtc.setAlarmMode (1 ); // Set the RTC alarm interval to a year, not particularly important if you are rolling alarms
51
+ // typical use case for this would be "I want an alarm every day at XX:YY:ZZ.WWW time" if this
52
+ // was the case you would want to 4 (every day). since we are setting a new alarm when the previous
53
+ // is triggered we would want this to just be larger than the largest period between alarms
51
54
rtc.attachInterrupt (); // Attach RTC alarm interrupt
52
55
53
56
// Print the RTC's alarm date and time
@@ -65,14 +68,16 @@ void loop()
65
68
// Clear alarm flag
66
69
alarmFlag = false ;
67
70
71
+ int secs = (rtc.seconds + alarmSeconds);
72
+ int mins = (rtc.minute + alarmMinutes + (int )(secs/60 ));
73
+ int hours = (rtc.hour + alarmHours + (int )(mins/60 ));
68
74
// Set the RTC's rolling alarm
69
75
rtc.setAlarm (0 ,
70
- (rtc. seconds + alarmSeconds) % 60 ,
71
- (rtc. minute + alarmMinutes) % 60 ,
72
- (rtc. hour + alarmHours) % 24 ,
76
+ secs % 60 ,
77
+ mins % 60 ,
78
+ hours % 24 ,
73
79
rtc.dayOfMonth ,
74
80
rtc.month );
75
- rtc.setAlarmMode (6 );
76
81
77
82
// Print next RTC alarm date and time
78
83
Serial.print (" Next rolling alarm: " ); printAlarm ();
0 commit comments