From d9bf83281d86acdcd5f5d3c111090b89ff70c754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Kub=C3=AD=C4=8Dek?= Date: Wed, 10 Jun 2026 08:36:12 +0200 Subject: [PATCH] =?UTF-8?q?P=C5=99eps=C3=A1n=C3=AD=20tla=C4=8D=C3=ADtka=20?= =?UTF-8?q?na=20extern=C3=AD=20pullup,=20m=C3=ADsto=20intern=C3=ADho.=20Pr?= =?UTF-8?q?avd=C4=9Bpodobn=C4=9B=20hardware=20chyba.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/src/main.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/src/main.cpp b/src/src/main.cpp index f19e722..2682ee7 100644 --- a/src/src/main.cpp +++ b/src/src/main.cpp @@ -43,12 +43,11 @@ bool masked = false; volatile bool buttonPressed = false; constexpr unsigned long DEBOUNCE_MS = 50; unsigned long lastButtonTime = 0; +volatile unsigned long buttonPressTime = 0; void onButtonPress() { - if (const unsigned long now = millis(); now - lastButtonTime >= DEBOUNCE_MS) { - lastButtonTime = now; - buttonPressed = true; - } + buttonPressTime = millis(); + buttonPressed = true; } String formatCode(const int value) { @@ -209,7 +208,7 @@ void setup() { lcd.printstr("NastavujiSePiny."); Serial.println("Nastavování pinů"); - pinMode(BUTTON_PIN, INPUT_PULLDOWN); Serial.println("Piny: 1/8"); + pinMode(BUTTON_PIN, INPUT); Serial.println("Piny: 1/8"); pinMode(RGB_RED_PIN, OUTPUT); Serial.println("Piny: 2/8"); pinMode(RGB_GREEN_PIN, OUTPUT); Serial.println("Piny: 3/8"); pinMode(RGB_BLUE_PIN, OUTPUT); Serial.println("Piny: 4/8"); @@ -229,6 +228,15 @@ void setup() { } void loop() { + if (buttonPressed) { + if (millis() - buttonPressTime >= DEBOUNCE_MS) { + buttonPressed = false; + // handle the press + } else { + buttonPressed = false; // too fast, ignore + } + } + if (Serial.available()) { String cmd = Serial.readStringUntil('\n'); cmd.trim();