SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
pcf8563_alarm.ino
Go to the documentation of this file.
1
30#include <RtcDrv.hpp>
31
32#ifndef SENSOR_SDA
33#define SENSOR_SDA 42
34#endif
35
36#ifndef SENSOR_SCL
37#define SENSOR_SCL 41
38#endif
39
40#ifndef SENSOR_IRQ
41#define SENSOR_IRQ 14
42#endif
43
44
46
47uint32_t intervalue = 0;
48uint8_t nextHour = 22;
49uint8_t nextMonth = 1;
50uint8_t nextDay = 1;
51uint8_t nextMinute = 59;
52uint8_t nextSecond = 55;
53
54
55void setup()
56{
57 Serial.begin(115200);
58 while (!Serial);
59
60 if (!rtc.begin(Wire, SENSOR_SDA, SENSOR_SCL)) {
61 Serial.println("Failed to find PCF8563 - check your wiring!");
62 while (1) {
63 delay(1000);
64 }
65 }
66
67 pinMode(SENSOR_IRQ, INPUT_PULLUP);
68
70
71 // From minute timer
73
75
76}
77
79{
80 if (millis() - intervalue > 1000) {
83
92 Serial.println(rtc.strftime());
93
94 intervalue = millis();
95 }
96}
97
98// Test minute timing
100{
101 while (1) {
102 if (digitalRead(SENSOR_IRQ) == LOW) {
103 Serial.println("testAlarmMinute Interrupt .... ");
104 if (rtc.isAlarmActive()) {
105 Serial.println("Alarm active");
106 rtc.resetAlarm();
108 nextHour++;
109 if (nextHour >= 24) {
110 nextHour = 23;
111 nextDay = 25;
113 Serial.println("setAlarmByHours");
114 return;
115 }
116 }
117 }
119 }
120}
121
122// Test hour timing
124{
125 while (1) {
126 if (digitalRead(SENSOR_IRQ) == LOW) {
127 Serial.println("testAlarmHour Interrupt .... ");
128 if (rtc.isAlarmActive()) {
129 Serial.println("Alarm active");
130 rtc.resetAlarm();
132 nextDay++;
133 if (nextDay >= 30) {
134 nextMonth = 1;
135 nextHour = 23;
136 nextMinute = 59;
137 nextSecond = 55;
141 Serial.println("setAlarmByDays");
142 return;
143 }
144 }
145 }
147 }
148}
149
150// Test day timing
152{
153 while (1) {
154 if (digitalRead(SENSOR_IRQ) == LOW) {
155 Serial.println("testAlarmDay Interrupt .... ");
156 if (rtc.isAlarmActive()) {
157 Serial.println("Alarm active");
158 rtc.resetAlarm();
161 nextMonth++;
162 if (nextMonth >= 12) {
163 return;
164 }
165 }
166 }
168 }
169}
170
171
172
173
174void loop()
175{
178 testAlarmDay();
179
180 Serial.println("Test done ...");
181 while (1) {
182 delay(100);
183 }
184}
185
186
187
@license MIT License
Driver for the PCF8563 real-time clock (RTC) over I2C.
void resetAlarm()
Clear the alarm flag.
void setDateTime(RTC_DateTime datetime) override
Set the RTC date/time.
void setAlarmByMinutes(uint8_t minute)
Convenience API to set an alarm that matches only minutes.
void setAlarmByDays(uint8_t day)
Convenience API to set an alarm that matches only day-of-month.
void setAlarmByHours(uint8_t hour)
Convenience API to set an alarm that matches only hours.
void enableAlarm()
Enable the alarm interrupt.
bool begin(SensorCommCustom::CustomCallback callback)
Initialize the device using a user-provided transport callback.
bool isAlarmActive()
Check whether the alarm flag is active.
uint8_t getDaysInMonth(uint8_t month, uint16_t year)
Get the number of days in a given month of a specific year, considering leap years.
Definition SensorRTC.h:552
const char * strftime(DateTimeFormat style=DT_FMT_YMD_HMS_WEEK)
Format the current date and time according to the specified style.
Definition SensorRTC.h:372
uint8_t nextMinute
SensorPCF8563 rtc
uint8_t nextSecond
void testAlarmMinute()
uint8_t nextHour
void testAlarmDay()
void setup()
uint8_t nextMonth
#define SENSOR_SCL
void testAlarmHour()
#define SENSOR_SDA
uint8_t nextDay
void printDateTime()
#define SENSOR_IRQ
uint32_t intervalue
void loop()