diff --git a/src/interval.cpp b/src/interval.cpp index 8f5546d..cdf029c 100644 --- a/src/interval.cpp +++ b/src/interval.cpp @@ -26,9 +26,13 @@ bool Interval::expired() } } else if (2 == _mode) { // periodic mode - if ((millis() - _timefrom) >= _timeout) { + const uint32_t now = millis(); + const uint32_t diff = now - _timefrom; + if (diff >= _timeout) { + const uint32_t times = diff / _timeout; + + _timefrom += _timeout * times; // more precise periodic timing result = true; - _timefrom += _timeout; // more precise periodic timing } } else { // compatibility mode