SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
pcf8563_time_lib.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
45uint32_t intervalue;
46char buf[64];
47
48void setup()
49{
50 Serial.begin(115200);
51 while (!Serial);
52
53 pinMode(SENSOR_IRQ, INPUT_PULLUP);
54
55 if (!rtc.begin(Wire, SENSOR_SDA, SENSOR_SCL)) {
56 Serial.println("Failed to find PCF8563 - check your wiring!");
57 while (1) {
58 delay(1000);
59 }
60 }
61
62 // The simplest way to set up
63 rtc.setDateTime(2024, 1, 17, 4, 21, 30);
64
65 // Unix tm structure sets the time
66 struct tm timeinfo;
67 timeinfo.tm_yday = 2025 - 1900; //Counting starts from 1900, so subtract 1900 here
68 timeinfo.tm_mon = 1 - 1; //Months start at 0, so you need to subtract 1.
69 timeinfo.tm_mday = 17;
70 timeinfo.tm_hour = 4;
71 timeinfo.tm_min = 30;
72 timeinfo.tm_sec = 30;
73 rtc.setDateTime(timeinfo);
74}
75
76
77void loop()
78{
79 if (millis() - intervalue > 1000) {
80
81 intervalue = millis();
82
83 struct tm timeinfo;
84 // Get the time C library structure
85 rtc.getDateTime(&timeinfo);
86
87 // Format the output using the strftime function
88 // For more formats, please refer to :
89 // https://man7.org/linux/man-pages/man3/strftime.3.html
90
91 size_t written = strftime(buf, 64, "%A, %B %d %Y %H:%M:%S", &timeinfo);
92
93 if (written != 0) {
94 Serial.println(buf);
95 }
96
97 written = strftime(buf, 64, "%b %d %Y %H:%M:%S", &timeinfo);
98 if (written != 0) {
99 Serial.println(buf);
100 }
101
102
103 written = strftime(buf, 64, "%A, %d. %B %Y %I:%M%p", &timeinfo);
104 if (written != 0) {
105 Serial.println(buf);
106 }
107 }
108}
109
110
111
@license MIT License
Driver for the PCF8563 real-time clock (RTC) over I2C.
void setDateTime(RTC_DateTime datetime) override
Set the RTC date/time.
bool begin(SensorCommCustom::CustomCallback callback)
Initialize the device using a user-provided transport callback.
RTC_DateTime getDateTime() override
Get the current RTC date/time.
SensorPCF8563 rtc
char buf[64]
void setup()
#define SENSOR_SCL
#define SENSOR_SDA
#define SENSOR_IRQ
uint32_t intervalue
void loop()