#include "TimeLib.h" // https://github.com/PaulStoffregen/Time
#include <Wire.h>
#include "DS1307RTC.h" // https://github.com/PaulStoffregen/DS1307RTC
#include "TimeAlarms.h" // https://github.com/PaulStoffregen/TimeAlarms
void print2digits(int v) {
if (v < 10) Serial.write('0');
Serial.print(v);
}
void printClock() {
Serial.print(hour());
Serial.write(':');
print2digits(minute());
Serial.write(':');
print2digits(second());
Serial.write('\t');
Serial.print(day());
Serial.write('/');
Serial.print(month());
Serial.write('/');
Serial.println(year());
}
void doSomething() {
Serial.println(F("Alarm: it's time to water the plants"));
}
void setup() {
Serial.begin(115200);
setSyncProvider(RTC.get); // the function to get the time from the RTC
if (timeStatus() != timeSet) {
Serial.println("Unable to sync with the RTC");
while (true) delay(1);
}
tmElements_t tm;
RTC.read(tm);
Serial.print("Setting the alarm at ");
Serial.print(tm.Hour);
Serial.write(':');
print2digits(tm.Minute+1);
Serial.write(':');
print2digits(0);
Serial.println();
Alarm.alarmRepeat(tm.Hour, tm.Minute + 1, 0, doSomething);
}
void loop() {
printClock();
Alarm.delay(1000);
}