Attempt to improve time tracking to improve stability

This commit is contained in:
Junior 2026-10-20 18:08:11 -04:00
parent d2848e84e9
commit 9d36a75875

View File

@ -69,15 +69,17 @@ unsigned long lastDebounceTime = 0;
bool actionState = false; bool actionState = false;
bool debouncing = false; bool debouncing = false;
void loop() { void loop() {
if ( millis() > (lastStatusTime + STATUSINTERVAL) ) { unsigned long currentMillis = millis();
if ( (currentMillis - lastStatusTime) >= STATUSINTERVAL ) {
lastStatusTime = sendDeviceStatus(); lastStatusTime = sendDeviceStatus();
currentMillis = lastStatusTime;
} }
unsigned short buttonCheck = digitalRead(BUTTONPIN); unsigned short buttonCheck = digitalRead(BUTTONPIN);
if ( buttonCheck != lastButtonState ) { if ( buttonCheck != lastButtonState ) {
debouncing = true; debouncing = true;
lastDebounceTime = millis(); lastDebounceTime = currentMillis;
} }
if ( debouncing && (millis() >= (lastDebounceTime + DEBOUNCEMS)) ) { if ( debouncing && (currentMillis >= (lastDebounceTime + DEBOUNCEMS)) ) {
debouncing = false; debouncing = false;
if ( buttonCheck != buttonState ) { if ( buttonCheck != buttonState ) {
buttonState = buttonCheck; buttonState = buttonCheck;