ds1307 timer problem

johnny78

Full Member level 5
Joined
Jun 28, 2017
Messages
265
Helped
1
Reputation
2
Reaction score
5
Trophy points
1,298
Activity points
3,424
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

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 time
any better idea ?
 
Last edited:

Hi,

I´d
* use a software clock ... and every minute at second 00 update the outputs.
* Update the software clock from DS1307 once at start up and then maybe once a day at midnight.

***
But indeed building a alarm clock with DS1307 involved is done many thousands times before.
Thus there is code available ... for almost any clock feature ...
Documents, web pages, code examples, explanations ... even videos

Klaus
 

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…