From 9d36a758756f5c2aed8ceade38f91e7ebf115dfd Mon Sep 17 00:00:00 2001 From: Junior Date: Tue, 20 Oct 2026 18:08:11 -0400 Subject: [PATCH] Attempt to improve time tracking to improve stability --- src/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index fb3eb64..d22cb38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -69,15 +69,17 @@ unsigned long lastDebounceTime = 0; bool actionState = false; bool debouncing = false; void loop() { - if ( millis() > (lastStatusTime + STATUSINTERVAL) ) { + unsigned long currentMillis = millis(); + if ( (currentMillis - lastStatusTime) >= STATUSINTERVAL ) { lastStatusTime = sendDeviceStatus(); + currentMillis = lastStatusTime; } unsigned short buttonCheck = digitalRead(BUTTONPIN); if ( buttonCheck != lastButtonState ) { debouncing = true; - lastDebounceTime = millis(); + lastDebounceTime = currentMillis; } - if ( debouncing && (millis() >= (lastDebounceTime + DEBOUNCEMS)) ) { + if ( debouncing && (currentMillis >= (lastDebounceTime + DEBOUNCEMS)) ) { debouncing = false; if ( buttonCheck != buttonState ) { buttonState = buttonCheck;