Hi,
I'm programming a countdown timer for our schoollessons. So the students can see how much time is over in a lesson.
The lessons are 45 minutes, the pauses 15 minutes.
Now, I start with a number of 2700000 milliseconds and every 1000 milliseconds I substract 1000 from that starting number. I use therefor the blink-without-delay-method.
Very simple, but it works.
One thing: the whole loop takes a bit of time too. So, when I countdown a second, it will be a bit more then a second, i think?
Would it be more accurate when I 'm using an RTC? Or is the deviation small enough for one whole day?
You think wrong. The millis counter us updated by interrupts so unless you have anything that disables the interrupts in your code you will not loose any time because if that.
The accuracy is determined by how accurate your crystal or resonator is.
if you use millis() you'll be dependant on the quality of the 16Mhz circuit that is used in your Arduino.
Typical Arduinos do have a ceramic resonator instead of a good crystal. The tolerance range for crystals is pretty narrow, but with ceramic resonators you never know.
If I remember well, you get ±-0.5% accuracy for the ceramic resonators so you could be off by 3 minutes at the end of a 10 hours day (8am to 6pm).
a cheap half baked solution would be to measure how much you gain / loose with your specific arduino in a typical day (temperature could impact this) and put some stuff in the code to take this into account (as you know how fast/slow your clock really is).
Using a good RTC (DS3231 or better) would be more precise but you probably need a way to sync to a "real clock" (NTP if you have internet access from your Arduino, GPS signal etc) from time to time to accommodate for small imprecision over time.
There is an 7-segment display, based on a ledstrip, connected.
And it must switch between lessons and pauses.
And there is an option to show the clock (an rtc is already in use, but not in the countdown part).
Then a DS3231 is not needed if you have internet near.
The WeMos D1 mini has a crystal clock, and will keep perfect time between (daily?) internet NTP updates.
Leo..