Buenas de nuevo, he hecho este simple codigo, pero no hace nada a la hora que le indico.
Cual puede ser el fallo?
// Alarma Chalet
#include <Wire.h> // Libreria para I2C
#include <LiquidCrystal_I2C.h> // Libreria para LCD
#define DS1307_I2C_ADDRESS 0x68 // Direccion bus Reloj
LiquidCrystal_I2C lcd(0x27,16,2); // Direccion de bus pantalla
int ledEstado = 13; // Led en pin 13 salto Pir 1 y Pir 2
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convierte BCD (binario decimal codificado) a números normales decimales
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.send(decToBcd(second));
Wire.send(decToBcd(minute));
Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));
Wire.send(decToBcd(dayOfMonth));
Wire.send(decToBcd(month));
Wire.send(decToBcd(year));
Wire.endTransmission();
}
// Establece la fecha y la hora del reloj
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
// Resetea el registro puntero
Wire.beginTransmission(DS1307_I2C_ADDRESS);
Wire.send(0);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// Alguno de estos necesitan enmascarar porque ciertos bits son bits de control
*second = bcdToDec(Wire.receive() & 0x7f);
*minute = bcdToDec(Wire.receive());
*hour = bcdToDec(Wire.receive() & 0x3f);
*dayOfWeek = bcdToDec(Wire.receive());
*dayOfMonth = bcdToDec(Wire.receive());
*month = bcdToDec(Wire.receive());
*year = bcdToDec(Wire.receive());
}
void setup()
{
lcd.init(); // Inicializacion LCD
lcd.backlight(); // Iluminacion LCD
pinMode(ledEstado, OUTPUT); // Funcion de salida LedEstado pin 13
Serial.begin(9600); // Puerto serie configurado a 9600 baudios.
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin();
// la primera vez debemos poner en hora, active esta parte y luego vuelva a quitarla
/*second = 00;
minute = 33;
hour = 15;
dayOfWeek = 6;
dayOfMonth = 11;
month = 2;
year = 12;
setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year); */
}
void loop()
{
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
lcd.setCursor(6,0);
lcd.print(year, DEC);
lcd.setCursor(2,0);
lcd.print("/");
lcd.setCursor(3,0);
if (month < 10) lcd.print("0");
lcd.print(month, DEC);
lcd.setCursor(5,0);
lcd.print("/");
lcd.setCursor(0,0);
if (dayOfMonth < 10) lcd.print("0");
lcd.print(dayOfMonth, DEC);
lcd.print("");
lcd.setCursor(0,1);
if (hour < 10) lcd.print("0");
lcd.print(hour, DEC);
lcd.setCursor(2,1);
lcd.print(":");
lcd.setCursor(3,1);
if (minute < 10) lcd.print("0");
lcd.print(minute, DEC);
lcd.setCursor(5,1);
lcd.print(":");
if (second < 10) lcd.print("0");
lcd.print(second, DEC);
switch (dayOfWeek)
{
case 1:
lcd.setCursor(9,0);
lcd.print("Lunes");
break;
case 2:
lcd.setCursor(9,0);
lcd.print("Martes");
break;
case 3:
lcd.setCursor(9,0);
lcd.print("Miercoles");
break;
case 4:
lcd.setCursor(9,0);
lcd.print("Jueves");
break;
case 5:
lcd.setCursor(9,0);
lcd.print("Viernes");
break;
case 6:
lcd.setCursor(9,0);
lcd.print("Sabado");
break;
case 7:
lcd.setCursor(9,0);
lcd.print("Domingo");
break;
}
delay(1000); //Pausa durante 1 segundo
//A las 12:40 se encienden 100% luces
if (hour == 12 && minute == 40)
{
digitalWrite (ledEstado, HIGH);
}
}
Saludos
Edito: buenas, ya he conseguido que se enciendan y apaguen a la hora que yo quiero, pero lo que no consigo es que lo haga a distintos dias de la semana, haciendolo de la siguiente manera:
//A las 12:40 se encienden 100% luces
if(dayOfMonth == 27 && hour == 12 && minute == 40)
{
digitalWrite (ledEstado, HIGH);
}