#include <LiquidCrystal.h>
// Definir pines para LCD
const int rs = 13, en = 12, d4 = 11, d5 = 10, d6 = A0, d7 = A1;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//Liberrias para RTC DS1307
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
String dias[7] = { "Domingo", "Lunes", "Martes", "Miercoles", "Jueves",
"Viernes", "Sabado"
};
String meses[12] = { "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio",
"Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"
};
void setup() {
Serial.begin(9600); //Iniciamos el serial monitor
if (!rtc.begin()) {
Serial.println(F("No se encuentra el dispositivo"));
while (1)
;
}
lcd.begin(16, 2); // Inicializar LCD con 16 columnas y 2 filas
lcd.clear(); // limpiamos el LCD
// Ajustar la fecha y hora del RTC a 17/09/2024 17:50:00
rtc.adjust(DateTime(2024, 9, 17, 13, 38, 0));
}
void loop() {
// Obtener fecha actual
DateTime tiempo = rtc.now();
String diaSemana = dias[tiempo.dayOfTheWeek()];
String diaMes = String(tiempo.day(), DEC);
String mes = meses[tiempo.month() - 1];
String anio = String(tiempo.year(), DEC);
String hora = String(tiempo.hour(), DEC);
String minuto = String(tiempo.minute(), DEC);
String segundo = String(tiempo.second(), DEC);
// Mostrar en Serial
Serial.print(diaSemana);
Serial.print(" ");
Serial.print(diaMes);
Serial.print(" de ");
Serial.print(mes);
Serial.print(" de ");
Serial.print(anio);
Serial.print(" | ");
Serial.print(hora);
Serial.print(':');
Serial.print(minuto);
Serial.print(':');
Serial.println(segundo);
// Mostrar en LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(diaSemana.substring(0, 3)); // Mostrar solo los primeros 3 caracteres del día de la semana
lcd.print(" ");
lcd.print(diaMes);
lcd.print("/");
lcd.print(tiempo.month());
lcd.print("/");
lcd.print(anio.substring(2)); // Mostrar solo los últimos dos dígitos del año
lcd.setCursor(0, 1);
lcd.print(hora);
lcd.print(':');
if (minuto.length() < 2) {
lcd.print('0');
}
lcd.print(minuto);
lcd.print(':');
if (segundo.length() < 2) {
lcd.print('0');
}
lcd.print(segundo);
delay(1000);
}