forked from arduino-libraries/Arduino_MachineControl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRTC_Alarm.ino
77 lines (63 loc) · 1.93 KB
/
RTC_Alarm.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Portenta Machine Control - RTC Alarm Example
*
* This sketch shows the usage of the RTC PCF8563T on the Machine
* Control Carrier and demonstrates how to configure and utilize the PCF8563T's alarm.
*
* Circuit:
* - Portenta H7
* - Portenta Machine Control
*
* Initial author: Riccardo Rizzo @Rocketct
*/
#include <Arduino_MachineControl.h>
int hours = 12;
int minutes = 45;
int seconds = 57;
bool alarm_flag = false;
int counter = 1;
void callback_alarm();
void setup() {
Serial.begin(9600);
while (!Serial) {
;
}
Serial.print("RTC Initialization");
if(!MachineControl_RTCController.begin()) {
Serial.println(" fail!");
}
Serial.println(" done!");
// APIs to set date's fields: hours, minutes and seconds
MachineControl_RTCController.setHours(hours);
MachineControl_RTCController.setMinutes(minutes);
MachineControl_RTCController.setSeconds(seconds);
// Enables Alarm on PCF8563T
MachineControl_RTCController.enableAlarm();
// set the minutes at which the alarm should rise
MachineControl_RTCController.setMinuteAlarm(46);
// Attach an interrupt to the RTC interrupt pin
attachInterrupt(RTC_INT, callback_alarm, FALLING);
}
void loop() {
if (alarm_flag) {
Serial.println("Alarm!!");
detachInterrupt(RTC_INT);
MachineControl_RTCController.setSeconds(seconds);
MachineControl_RTCController.setMinuteAlarm(minutes + counter);
MachineControl_RTCController.clearAlarm();
attachInterrupt(RTC_INT, callback_alarm, FALLING);
alarm_flag = false;
// To disable the alarm uncomment the following line:
// MachineControl_RTCController.disableAlarm();
}
// APIs to get date's fields
Serial.print(MachineControl_RTCController.getHours());
Serial.print(":");
Serial.print(MachineControl_RTCController.getMinutes());
Serial.print(":");
Serial.println(MachineControl_RTCController.getSeconds());
delay(1000);
}
void callback_alarm () {
alarm_flag = true;
}