/*
https://github.com/Makuna/Rtc
Arduino Real Time Clock library.
*/
#include <SoftwareWire.h> // must be included here so that Arduino library object file references work
#include <RtcDS3231.h>
SoftwareWire myWire(6, 5); // SDA, SCL
RtcDS3231<SoftwareWire> Rtc(myWire);
void setup() {
Serial.begin(9600);
Rtc.Begin();
//RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
//Rtc.SetDateTime(compiled + 0*60*60 + 8);
//Rtc.SetDateTime(RtcDateTime(2018, 1, 17, 7, 53, 00));
}
void loop() {
static char date[11];
static char time[9];
RtcDateTime dt = Rtc.GetDateTime();
bool rtclock_err = !Rtc.IsDateTimeValid();
snprintf(date, 11, "%04u-%02u-%02u", dt.Year(), dt.Month(), dt.Day());
snprintf(time, 9, "%02d:%02d:%02d", dt.Hour(), dt.Minute(), dt.Second());
Serial.print(date);
Serial.print(" ");
Serial.print(time);
if (rtclock_err) Serial.print(" rtclock ER");
else Serial.println(" rtclock OK");
Serial.println("");
delay(300);
}