Hi everyone, I have a proyect to turn ON and OFF a light at a time setted by the user. The user could change the time when ever he wants.
I wrote a code but it isn't workin. I just want to know if the logic is OK
I attach the code of the function here.
Thanks!
void Light_ON_OFF(void)
{
byte hs_actual=rtc.getHours();
byte min_actual=rtc.getMinutes();
//Declare aux variables to concatenate hours and minutes to treat them as only 1 variable
int aux_setted_off, aux_setted_on, actual
aux_setted_off=encendido=actual=0;
//Concatenates hour and minutes. Setted by te user and the actual time
aux_setted_off=hs_setted_off*100+min_setted_off;
aux_setted_on=hs_setted_on*100+min_setted_on;
aux_actual=hs_actual*100+min_actual;
if(aux_setted_off<aux_setted_on)
{
if(aux_actual>=aux_setted_off && aux_actual<aux_setted_on)
digitalWrite(PIN_LIGHT, 0); //Turn lights OFF
else
digitalWrite(PIN_LIGHT, 1); //Turn lights ON
}
if(aux_setted_off>aux_setted_on)
{
if(aux_actual>=aux_setted_on && aux_actual<aux_setted_off)
digitalWrite(PIN_LIGHT, 1); //Turn lights ON
else
digitalWrite(PIN_LIGHT, 0); //Turn lights OFF
}
}
ON_OFF.c (960 Bytes)