#include <LiquidCrystal_I2C_Hangul.h>
#include "RTClib.h"
LiquidCrystal_I2C_Hangul lcd(0x27, 20, 4);
RTC_DS1307 rtc;
int timbre = 2;
String tipo = " horario/ 8:00-4:00 ";
String reloj = "";
String fecha = "";
char daysOfTheWeek[7][12] = {"domingo", "lunes", "Martes", "miercoles", "jueves", "viernes", "sabado"};
// Horarios para diferentes tipos (4 columnas)
/*
const String Hor[12][4] = {
{"7:50:0", "7:50:0", "7:50:0", "7:50:0"},
{"8:00:0", "8:00:0", "8:00:0", "8:00:0"},
{"8:50:0", "8:40:0", "8:30:0", "8:30:0"},
{"9:40:0", "9:20:0", "9:00:0", "9:00:0"},
{"10:20:0", "10:00:0", "9:30:0", "9:30:0"},
{"10:50:0", "10:30:0", "10:00:0", "10:00:0"},
{"11:40:0", "11:10:0", "10:30:0", "10:30:0"},
{"12:30:0", "11:50:0", "11:00:0", "11:00:0"},
{"13:30:0", "12:30:0", "11:30:0", "11:30:0"},
{"14:15:0", "13:30:0", "12:00:0", "12:00:0"},
{"15:00:0", "14:20:0", "12:30:0", "12:30:0"},
{"15:45:0", "15:10:0", "13:00:0", "13:00:0"}
};
*/
int tipoHorario = 0;
String formatoHora(int h, int m, int s) {
char buffer[9];
sprintf(buffer, "%d:%d:%d", h, m, s);
return String(buffer);
}
void sonarTimbre() {
digitalWrite(timbre, HIGH);
delay(5000);
digitalWrite(timbre, LOW);
}
void setup() {
Serial.begin(115200);
lcd.init();
lcd.clear();
pinMode(timbre, OUTPUT);
if (!rtc.begin()) {
Serial.println("RTC no conectada");
Serial.flush();
abort();
}
lcd.setCursor(0, 0);
lcd.print(" IPJDG");
lcd.setCursor(0, 1);
lcd.print(tipo);
}
void loop() {
DateTime now = rtc.now();
reloj = formatoHora(now.hour(), now.minute(), now.second());
fecha = String(daysOfTheWeek[now.dayOfTheWeek()]) + " " +
String(now.day()) + "/" + String(now.month()) + "/" + String(now.year());
lcd.setCursor(0, 3);
lcd.print("Hora: " + reloj + " ");
lcd.setCursor(0, 2);
lcd.print("Fecha: " + fecha);
Serial.println("Hora actual: " + reloj);
for (int i = 0; i < 12; i++) {
if (reloj == Hor[i][tipoHorario]) {
sonarTimbre();
delay(1000);
break;
}
}
delay(1000);
}
1
2
3
4