This example demonstrate how to use the RTC library methods in order to do something when an alarm is matched. In particular in this example, the RTC time is set at 16:00:00 and an alarm at 16:00:10. When the time match using the match type
MATCH_HHMMSS
is reached, the attached interrupt function will print on the serial monitor Alarm Match!.Only your Arduino Board is needed for this example.
1/*2
3 Simple RTC Alarm for Arduino Zero and MKR10004
5 Demonstrates how to set an RTC alarm for the Arduino Zero and MKR10006
7 This example code is in the public domain8
9 https://www.arduino.cc/en/Tutorial/SimpleRTCAlarm10
11 created by Arturo Guadalupi <a.guadalupi@arduino.cc>12
13 25 Sept 201514
15
16
17 modified18
19 21 Oct 201520
21*/22
23#include <RTCZero.h>24
25/* Create an rtc object */26
27RTCZero rtc;28
29/* Change these values to set the current initial time */30
31const byte seconds = 0;32
33const byte minutes = 0;34
35const byte hours = 16;36
37/* Change these values to set the current initial date */38
39const byte day = 25;40
41const byte month = 9;42
43const byte year = 15;44
45void setup()46{47
48 Serial.begin(9600);49
50 rtc.begin(); // initialize RTC 24H format51
52 rtc.setTime(hours, minutes, seconds);53
54 rtc.setDate(day, month, year);55
56 rtc.setAlarmTime(16, 0, 10);57
58 rtc.enableAlarm(rtc.MATCH_HHMMSS);59
60
61
62 rtc.attachInterrupt(alarmMatch);63}64
65void loop()66{67
68}69
70void alarmMatch()71{72
73 Serial.println("Alarm Match!");74}