From e7bbf45a9fdfd7724759ae43114da154b9b06486 Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Sat, 29 Mar 2025 14:23:55 +0100 Subject: [PATCH] fix: add debounce handling for TTP223 touch sensor --- src/main.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 69b00aa..4098ca6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -87,17 +87,23 @@ uint8_t autoAmsCounter = 0; uint8_t weightSend = 0; int16_t lastWeight = 0; +// WIFI check variables unsigned long lastWifiCheckTime = 0; const unsigned long wifiCheckInterval = 60000; // Überprüfe alle 60 Sekunden (60000 ms) +// Button debounce variables +unsigned long lastButtonPress = 0; +const unsigned long debounceDelay = 500; // 500 ms debounce delay + // ##### PROGRAM START ##### void loop() { unsigned long currentMillis = millis(); // Überprüfe den Status des Touch Sensors - if (digitalRead(TTP223_PIN) == LOW) + if (digitalRead(TTP223_PIN) == LOW && currentMillis - lastButtonPress > debounceDelay) { - tareScale(); + lastButtonPress = currentMillis; + scaleTareRequest = true; } // Überprüfe regelmäßig die WLAN-Verbindung