Methods For Setting The Time
Setting the time on any microcontroller-driven clock is an important task, one most people avoid when planning the clock. This repo offers a couple of solutions to the problem of setting the time. Although there are good ways for dealing with time, these examples do not use them so that they can be adapted for any approach you want to take:
Paul Stoffregen's Time library contains an example which uses the POSIX epoch string to set the time as a single number. Paul's Time library is the easiest way to deal with time if you're using a microcontroller with no realtime clock. It can also handle external realtime clocks as well. If you're using any of the microcontrollers with the ARM M0+ processor, the Arduino RTC library does a good job as well.
- Setting the time from the compiler time string. This uses the time from the computer that compiled your sketch to set the time. There are two special strings,
__DATE__that you can use to get an initial time and date.
- Setting the time from a serial input string. This idea, borrowed from Stoffregen's TimeSerial example but using the format of the previous method, gets the time from a serial input string.
- Setting the time from physical controls. Pushbuttons and rotary encoders are common on inexpensive clocks. You can use these to change the time on your clock too.