Arduino Software RTC Control.

I've been looking at the date time library and was wondering if there is a way to turn something on at a certain time. The date time library grabs date and time from the computer. I would like to have it turn on leds at a certain time or some other thing. I need help on the code part. I know how I want to build the circuit.

Coding with time has one major difficulty, the clock advances while your code executes.

This means that if you compare minutes and seconds, the clock just might jump a second between those two compares which can cause trouble.
compare these two lines of code

if (min == 10 && sec == 30) ...

if (sec == 30 && min == 10) ...

For both lines there is a scenario abour 10:29-10:30 in which the compare failes just because the seconds increases around the test.

The way to solve this is

  • use a timestamp (e.g. unix timestamp == seconds since 1-1-1970
  • or use in equalities
    if (sec >=30 && min == 10) ..
    This won't miss a jump of a second, OK it introduces a chance f executing things twice but that can be solved by flagging a statement as executed.

Hopes this helps you in the right direction.

Search the blink without delay example on the tutorial for how to handle time (slightly different but in essence the same)