#include <RTClib.h>
// event from 13:50 to 14:10
uint8_t DAILY_EVENT_START_HH = 14; // event start time: hour
uint8_t DAILY_EVENT_START_MM = 20; // event start time: minute
uint8_t DAILY_EVENT_END_HH = 14; // event end time: hour
uint8_t DAILY_EVENT_END_MM = 40; // event end time: minute
RTC_DS1307 rtc;
char daysOfTheWeek[7][12] = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
};
void setup () {
pinMode(4, OUTPUT);
Serial.begin(9600);
// SETUP RTC MODULE
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
// sets the RTC to the date & time on PC this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// sets the RTC with an explicit date & time, for example to set
// January 21, 2021 at 3am you would call:
// rtc.adjust(DateTime(2021, 1, 21, 3, 0, 0));
}
void loop () {
DateTime now = rtc.now();
if (now.hour() >= DAILY_EVENT_START_HH &&
now.minute() >= DAILY_EVENT_START_MM &&
now.hour() < DAILY_EVENT_END_HH &&
now.minute() < DAILY_EVENT_END_MM) {
Serial.println("It is on scheduled time");
delay(100);
digitalWrite(4, HIGH);
// TODO: write your code"
} else {
Serial.println("It is NOT on scheduled time");
delay(100);
digitalWrite(4, LOW);
}
printTime(now);
delay(10000)
}
void printTime(DateTime time) {
Serial.print("TIME: ");
Serial.print(time.year(), DEC);
Serial.print('/');
Serial.print(time.month(), DEC);
Serial.print('/');
Serial.print(time.day(), DEC);
Serial.print(" (");
Serial.print(daysOfTheWeek[time.dayOfTheWeek()]);
Serial.print(") ");
Serial.print(time.hour(), DEC);
Serial.print(':');
Serial.println(time.minute(), DEC);
Serial.print(':');
//Serial.println(time.second(), DEC);
}