Přepsání tlačítka na externí pullup, místo interního. Pravděpodobně hardware chyba.

This commit is contained in:
Matěj Kubíček
2026-06-10 08:36:12 +02:00
parent 31b496cef2
commit d9bf83281d
+12 -4
View File
@@ -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;
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();