Hi, im trying light on and off two lights at different times... (first one, and when still that light is on, start the second..... then, in the night off the first and after 30 minutes off the second) but dont work...
I think because "if "and "else if" exclude each other........ but dont know how to do this.
this is my code.
#include <Wire.h>
#include "RTClib.h"
RTC_DS1307 rtc;
int segundo,minuto,hora,dia,mes,diaDeLaSemana;
DateTime HoraFecha;
void setup () {
Serial.begin(9600);
rtc.begin(); //Inicializamos el RTC
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
void loop () {
HoraFecha = rtc.now(); //obtenemos la hora y fecha actual
segundo=HoraFecha.second();
minuto=HoraFecha.minute();
hora=HoraFecha.hour();
diaDeLaSemana=HoraFecha.dayOfTheWeek(); //0:Dominogo, 1:Lunes, 2:Martes ...
float horas=hora+minuto/60.0;
//condicion: >3pm y <24pm
if(horas>13.5&&horas<14.5)
{
digitalWrite(2, HIGH);
Serial.print("Salida digital 2 = ON");
}
//condicion: >3.5pm y <24.5am
else if (horas>14&&horas<15)
{
digitalWrite(3, HIGH);
Serial.print("Salida digital 3 = ON");
}
else
{
digitalWrite(2, LOW);
delay(1000);
digitalWrite(3, LOW);
Serial.print("Salida digital 2 = OFF");
}
//Enviamos por el puerto serie la hora y fecha.
Serial.print(" hora = ");
Serial.print(hora);
Serial.print(":");
Serial.print(minuto);
Serial.print(":");
Serial.print(segundo);
Serial.print(" dia de La semana = ");
Serial.print(HoraFecha.dayOfTheWeek());
Serial.println();
delay(1000);
}]