johnny78
Full Member level 5
hi Guys
im using arduino uno with ds1307 as a timer to turn on and off outputs
here is the code to get the time from the RTC
here is the code to turn on & off at specified time
the code is working but if i set on time (for example) to 23:00 & off time to 02:00 its not working
any idea to calculate the stop time will be great
thanks
Johnny
any better idea ?
im using arduino uno with ds1307 as a timer to turn on and off outputs
here is the code to get the time from the RTC
Code:
tmElements_t tm;
strZero = ("0");
if (RTC.read(tm)) {
strHours = tm.Hour;
strMinutes = tm.Minute;
if ((tm.Minute) < 10) {
strMinutes = strZero + tm.Minute;
}
if ((tm.Hour) < 10) {
strHours = strZero + tm.Hour;/////////// new to fix the time display after 00:59
}
strSeperator = (":");
strTime = strHours + strSeperator + strMinutes;
here is the code to turn on & off at specified time
Code:
if ((out1TimeControl) == 0 && (settingsDisplay1) == 0) {
if ((tm.Hour) > out1OnTimeSetHours) {
if ((tm.Hour) <= out1OffTimeSetHours) {
out1TimeControl = 1;
}
}
if ((tm.Hour) >= out1OnTimeSetHours && (tm.Minute) >= out1OnTimeSetMinutes) {
if ((tm.Hour) <= out1OffTimeSetHours) {
out1TimeControl = 1;
}
}
}
if ((out1TimeControl) == 1 && (settingsDisplay1) == 0) {
if ((tm.Hour) >= out1OffTimeSetHours) {
if ((tm.Minute) >= out1OffTimeSetMinutes) {
out1TimeControl = 0;
}
}
}
the code is working but if i set on time (for example) to 23:00 & off time to 02:00 its not working
any idea to calculate the stop time will be great
thanks
Johnny
--- Updated ---
i was thinking of calculating the hours & minutes difference between On & Off timehi Guys
im using arduino uno with ds1307 as a timer to turn on and off outputs
here is the code to get the time from the RTC
Code:tmElements_t tm; strZero = ("0"); if (RTC.read(tm)) { strHours = tm.Hour; strMinutes = tm.Minute; if ((tm.Minute) < 10) { strMinutes = strZero + tm.Minute; } if ((tm.Hour) < 10) { strHours = strZero + tm.Hour;/////////// new to fix the time display after 00:59 } strSeperator = (":"); strTime = strHours + strSeperator + strMinutes;
here is the code to turn on & off at specified time
Code:if ((out1TimeControl) == 0 && (settingsDisplay1) == 0) { if ((tm.Hour) > out1OnTimeSetHours) { if ((tm.Hour) <= out1OffTimeSetHours) { out1TimeControl = 1; } } if ((tm.Hour) >= out1OnTimeSetHours && (tm.Minute) >= out1OnTimeSetMinutes) { if ((tm.Hour) <= out1OffTimeSetHours) { out1TimeControl = 1; } } } if ((out1TimeControl) == 1 && (settingsDisplay1) == 0) { if ((tm.Hour) >= out1OffTimeSetHours) { if ((tm.Minute) >= out1OffTimeSetMinutes) { out1TimeControl = 0; } } }
the code is working but if i set on time (for example) to 23:00 & off time to 02:00 its not working
any idea to calculate the stop time will be great
thanks
Johnny
any better idea ?
Last edited: