#include <LiquidCrystal_I2C.h>
#include <RTClib.h>
#include <TaskScheduler.h>
Scheduler runner;
RTC_DS1307 rtc;
LiquidCrystal_I2C lcd(0x27, 16, 2);
int hora;
int minutos;
int segundos;
int ledpin = 28;
Task tasca1(0, TASK_FOREVER, []() {
DateTime now = rtc.now();
hora=now.hour();
minutos=now.minute();
segundos=now.second();
// Display the date & time on the LCD
lcd.setCursor(6, 1);
lcd.print(hora, DEC);
lcd.print(':');
if (minutos < 10) {
lcd.print('0');
}
lcd.print(minutos, DEC);
lcd.print(':');
if (segundos < 10) {
lcd.print('0');
}
lcd.print(segundos, DEC);
delay(1000);
});
Task tasca2(0, TASK_FOREVER, []() {
Serial.println(hora);
if ((minutos == 0)&&(segundos == 0)) {
if (hora > 12) {
hora = hora % 12;
}
for (int i = 0; i <hora;i++){
digitalWrite(ledpin, HIGH);
delay(500);
digitalWrite(ledpin, LOW);
delay(500);
}
}
});
void setup() {
Serial.begin(9600);
pinMode(ledpin , OUTPUT );
// SETUP RTC MODULE
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
Serial.flush();
while (1);
}
// automatically sets the RTC to the date & time on the PC this sketch was compiled
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// manually sets the RTC with an explicit date & time, for example, to set
// January 21, 2021, at 3 am, you would call:
rtc.adjust(DateTime(2021, 1, 21, 11, 59, 56));
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
lcd.setCursor(0, 0);
lcd.print("Time: ");
runner.init();
runner.addTask(tasca1);
runner.addTask(tasca2);
tasca1.enable();
tasca2.enable();
}
void loop(){
runner.execute();
}