From d02bd77806d4b60ca2464f7c26e28275c92cdf21 Mon Sep 17 00:00:00 2001 From: Pablo2048 Date: Wed, 18 Dec 2024 17:23:04 +0100 Subject: [PATCH] Nespoustime expired() pro propasnute casy, ale presto udrzujeme presnost (snad). --- src/interval.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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