Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ds1307 timer problem

johnny78

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

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
i was thinking of calculating the hours & minutes difference between On & Off time
any better idea ?
 
Last edited:

LaTeX Commands Quick-Menu:

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top