I would like to use the RTC DS3231 as a reference for a millis timer. How can i use the time from the RTC module to do something every 20 hours?
#include <Wire.h> //I2C library
#include <RtcDS3231.h> //RTC library
unsigned long now = 0;
RtcDS3231<TwoWire> rtc(Wire);
void setup() {
Serial.begin(115200); //Starts serial connection
rtc.Begin(); //Starts I2C
}
void handleGetTime() {
RtcDateTime currentTime = rtc.GetDateTime(); //get the time from the RTC
char str[20]; //declare a string as an array of chars
sprintf(str, "%d/%d/%d %d:%d:%d", //%d allows to print an integer to the string
currentTime.Year(), //get year method
currentTime.Month(), //get month method
currentTime.Day(), //get day method
currentTime.Hour(), //get hour method
currentTime.Minute(), //get minute method
currentTime.Second() //get second method
);
Serial.println(str); //print the string to the serial port
}
void loop() {
if (millis() - now >= 1000) {
handleGetTime();
now = millis();
}
}
Dont think i can use a string as a number to compare with