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
(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 ;
}
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.
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