ropg / ezTime

ezTime — pronounced "Easy Time" — is a very easy to use Arduino time and date library that provides NTP network time lookups, extensive timezone support, formatted time and date strings, user events, millisecond precision and more.
MIT License
327 stars 92 forks source link

Problem with using minuteChanged and secondChanged together #53

Closed aussieW closed 5 years ago

aussieW commented 5 years ago

Hi

I am writing a program to display he time on an LED matrix. I used secondChanged to blink a colon between the hours and minutes and also manually tracked when the minute changed in order to update the time on the display. That worked fine.

I figured I could simplify things by using minuteChanged to trigger a screen refresh rather than tracking when the minute changed. However, when I use both minuteChanged and secondChanged together I find that secondChanged is being triggered approx 100,000 times per second rather than just once per second.

My questions are:

  1. should the combination of these two functions work as I expect, and there is a bug occurring?
  2. these two functions not designed to work together in the same program?

Thanks aussieW

ropg commented 5 years ago

You have to read the time using one of ezTime's functions (such as now()) for it to update _last_read_t, which is used internally to determine whether the seconds or minutes have changed since the last time the time was read. So just calling the function and then not reading the time when it returns true keeps it returning true. Just read the time with now() every time it has changed and you're fine.

aussieW commented 5 years ago

Thanks. Works great now.