DS3231 Clock & Time value

Hello

Using a DS3231 Real Time Clock and the DS1307RTC library
possibly theres a better library but thats the one iv got working - if theres a better one do say

Need a bit of advice/guidance on how to trigger an If statement with a time value.
I want the If statement to trigger for a time such as 15:45, the library doesn't appear to give me a direct '15:45' readout it does give hours and minuets separately - haven't actually tried it but I'm guessing the hours+minuets value wont work.

The minuets are given as part of 60 minuets in the hour, is there a way to get the minuets as part of the day as 15:45 = 945 minuets

Or maybe I'm wrong and theres another way to do this - a fairly simple way that will not burn out my remaining brain cells

Any help appreciated

haven't actually tried it but I'm guessing the hours+minuets value wont work.

Why not? Then, there would be no need to guess.

The minuets are given as part of 60 minuets in the hour, is there a way to get the minuets as part of the day as 15:45 = 945 minuets

(15 * 60) + 45 = 945

What's wrong with:

  if (hour == 15 && minutes == 45)
  {
  }

(Actually the answer is that this test will repeatedly trigger in loop()
for a whole minute, so you need a flag to say I've already triggered today,
or something like:

void loop ()
{
  read_time () ; // or whatever you need to read the variables

  if (hour == 15 && minutes >= 45 && prev_minutes < 45)
  {
    do_stuff () ;
  }
  ..
  ..
  prev_minutes = minutes ;
  prev_hours = hours ;
}

Hi
Apologies for taking ages to get back to this

PaulS
Yes i should have tried it, just didn't expect something so simple to work, it did - normally simple doesn't work

MarkT
Never got to considering the loop possibility - when the thing doesn't work as expected i'll know where to look

thanks for the help

Alternatively you could shift from doing calculations in terms of "human" time format and think in terms of epoch
time format which is the best way to track time for things like comparing dates/time.
When using an epoch, things like this can become easier because the datetime is a single value
usually representing seconds since an epoch.

The RTC is used to merely initialized the epoch time value and after that
everything is tracked and compared based on epoch values.

There are some other libraries that are very helpful as they can
do all the conversions and processing for you.
All these libraries work together and with the Time library.

Time library: (to do all the time keeping and conversions from/to epoch time to human time)
http://playground.arduino.cc/code/time

TimeAlarms: to set alarm events
(Included in Time library download image)

DS3232RTC: to handle reading the RTC and initializing the Time library epoch
(works on DS3231 as well)

TimeZone: to handle timezone conversions and Daylight savings shifts

--- bill

bperrybap
your given me a lot to think about there.
At the moment I've got most of the thing working on a breadboard and am starting to move it to its eventual housing, so for the time being I'll stick with what I've got - as its working.
You suggested approach I'll look at as 'version 2' and do a complete rebuild

thanks for the suggestions and thoughts