Necesito encender un led con un rtc 20 minutos cada 20 días pero no entiendo cómo funciona, es un rtc 1302
Es lo que tengo pero no entiendo
#include <RtcDS1302.h>
ThreeWire myWire(4,5,2);
RtcDS1302 Rtc(myWire);
const int LED_PIN = 6;
bool ledOn = false;
unsigned long timerStart;
const unsigned long TIMER_DURATION = 15 * 60 * 1000;
void setup ()
{
Serial.begin(57600);
Serial.print("compiled: ");
Serial.print(__DATE__);
Serial.println(__TIME__);
Rtc.Begin();
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
printDateTime(compiled);
Serial.println();
if (!Rtc.IsDateTimeValid())
{
Serial.println("RTC lost confidence in the DateTime!");
Rtc.SetDateTime(compiled);
}
if (Rtc.GetIsWriteProtected())
{
Serial.println("RTC was write protected, enabling writing now");
Rtc.SetIsWriteProtected(false);
}
if (!Rtc.GetIsRunning())
{
Serial.println("RTC was not actively running, starting now");
Rtc.SetIsRunning(true);
}
RtcDateTime now = Rtc.GetDateTime();
if (now < compiled)
{
Serial.println("RTC is older than compile time! (Updating DateTime)");
Rtc.SetDateTime(compiled);
}
else if (now > compiled)
{
Serial.println("RTC is newer than compile time. (this is expected)");
}
else if (now == compiled)
{
Serial.println("RTC is the same as compile time! (not expected but all is fine)");
}
pinMode(LED_PIN, OUTPUT);
}
void loop ()
{
RtcDateTime now = Rtc.GetDateTime();
printDateTime(now);
Serial.println();
if (now.Hour() == 10 && now.Minute() == 0 && !ledOn)
{
ledOn = true;
digitalWrite(LED_PIN, HIGH);
timerStart = millis();
Serial.println("LED on");
}
if (ledOn && millis() - timerStart >= TIMER_DURATION)
{
ledOn = false;
digitalWrite(LED_PIN, LOW);
Serial.println("LED off");
}
if (!now.IsValid())
{
Serial.println("RTC lost confidence in the DateTime!");
}
delay(10000);
}
#define countof(a) (sizeof(a) / sizeof(a[0]))
void printDateTime(const RtcDateTime& dt)
{
char datestring[20];
snprintf_P(datestring,
countof(datestring),
PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
dt.Month(),
dt.Day(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
Serial.print(datestring);
}