SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
pcf85063_alarm.ino
Go to the documentation of this file.
1
30#include <RtcDrv.hpp>
31
32#ifndef SENSOR_SDA
33#define SENSOR_SDA 4
34#endif
35
36#ifndef SENSOR_SCL
37#define SENSOR_SCL 5
38#endif
39
40#ifndef SENSOR_IRQ
41#define SENSOR_IRQ 14
42#endif
43
44
46
47
48uint32_t intervalue = 0;
49uint8_t nextHour = 22;
50uint8_t nextMonth = 1;
51uint8_t nextDay = 1;
52uint8_t nextMinute = 59;
53uint8_t nextSecond = 20;
54
55
56void setup()
57{
58 Serial.begin(115200);
59 while (!Serial);
60
61 if (!rtc.begin(Wire, SENSOR_SDA, SENSOR_SCL)) {
62 Serial.println("Failed to find PCF85063 - check your wiring!");
63 while (1) {
64 delay(1000);
65 }
66 }
67
68 pinMode(SENSOR_IRQ, INPUT_PULLUP);
69
71
72 nextSecond = 55;
73
74 // First test alarm seconds
76
78
79}
80
82{
83 if (millis() - intervalue > 1000) {
86
95 Serial.println(rtc.strftime());
96
97 intervalue = millis();
98 }
99}
100
101// Test seconds timing
103{
104 while (1) {
105 if (digitalRead(SENSOR_IRQ) == LOW) {
106 Serial.println("testAlarmSeconds Interrupt .... ");
107 if (rtc.isAlarmActive()) {
108 Serial.println("Alarm active");
109 rtc.resetAlarm();
112 return;
113 }
114 }
116 }
117}
118
119
120// Test minute timing
122{
123 while (1) {
124 if (digitalRead(SENSOR_IRQ) == LOW) {
125 Serial.println("testAlarmMinute Interrupt .... ");
126 if (rtc.isAlarmActive()) {
127 Serial.println("Alarm active");
128 rtc.resetAlarm();
130 nextHour++;
131 if (nextHour >= 24) {
132 nextHour = 23;
133 nextDay = 25;
135 Serial.println("setAlarmByHours");
136 return;
137 }
138 }
139 }
141 }
142}
143
144// Test hour timing
146{
147 while (1) {
148 if (digitalRead(SENSOR_IRQ) == LOW) {
149 Serial.println("testAlarmHour Interrupt .... ");
150 if (rtc.isAlarmActive()) {
151 Serial.println("Alarm active");
152 rtc.resetAlarm();
154 nextDay++;
155 if (nextDay >= 30) {
156 nextMonth = 1;
157 nextHour = 23;
158 nextMinute = 59;
159 nextSecond = 55;
163 Serial.println("setAlarmByDays");
164 return;
165 }
166 }
167 }
169 }
170}
171
172// Test day timing
174{
175 while (1) {
176 if (digitalRead(SENSOR_IRQ) == LOW) {
177 Serial.println("testAlarmDay Interrupt .... ");
178 if (rtc.isAlarmActive()) {
179 Serial.println("Alarm active");
180 rtc.resetAlarm();
183 nextMonth++;
184 if (nextMonth >= 12) {
185 return;
186 }
187 }
188 }
190 }
191}
192
193
194
195
196void loop()
197{
201 testAlarmDay();
202
203 Serial.println("Test done ...");
204 while (1) {
205 delay(100);
206 }
207}
208
209
210
@license MIT License
Driver for the PCF85063 real-time clock (RTC) over I2C.
void resetAlarm()
Clear/reset the alarm flag.
bool isAlarmActive()
Check whether the alarm flag is active.
void setDateTime(RTC_DateTime datetime) override
Set the RTC date and time.
void setAlarmByHours(uint8_t hour)
Convenience: enable only hour alarm.
bool begin(SensorCommCustom::CustomCallback callback)
Initialize device using a custom transport callback.
void enableAlarm()
Enable alarm interrupt/event generation.
void setAlarmByMinutes(uint8_t minute)
Convenience: enable only minute alarm.
void setAlarmBySecond(uint8_t second)
Convenience: enable only second alarm.
void setAlarmByDays(uint8_t day)
Convenience: enable only day-of-month alarm.
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
uint8_t nextSecond
SensorPCF85063 rtc
void testAlarmMinute()
uint8_t nextHour
void testAlarmDay()
void setup()
uint8_t nextMonth
#define SENSOR_SCL
void testAlarmHour()
#define SENSOR_SDA
void testAlarmSeconds()
uint8_t nextDay
void printDateTime()
#define SENSOR_IRQ
uint32_t intervalue
void loop()