Přepsání tlačítka na externí pullup, místo interního. Pravděpodobně hardware chyba.
This commit is contained in:
+13
-5
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user