Přepsání tlačítka na externí pullup, místo interního. Pravděpodobně hardware chyba.
This commit is contained in:
+12
-4
@@ -43,12 +43,11 @@ bool masked = false;
|
|||||||
volatile bool buttonPressed = false;
|
volatile bool buttonPressed = false;
|
||||||
constexpr unsigned long DEBOUNCE_MS = 50;
|
constexpr unsigned long DEBOUNCE_MS = 50;
|
||||||
unsigned long lastButtonTime = 0;
|
unsigned long lastButtonTime = 0;
|
||||||
|
volatile unsigned long buttonPressTime = 0;
|
||||||
|
|
||||||
void onButtonPress() {
|
void onButtonPress() {
|
||||||
if (const unsigned long now = millis(); now - lastButtonTime >= DEBOUNCE_MS) {
|
buttonPressTime = millis();
|
||||||
lastButtonTime = now;
|
|
||||||
buttonPressed = true;
|
buttonPressed = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String formatCode(const int value) {
|
String formatCode(const int value) {
|
||||||
@@ -209,7 +208,7 @@ void setup() {
|
|||||||
lcd.printstr("NastavujiSePiny.");
|
lcd.printstr("NastavujiSePiny.");
|
||||||
Serial.println("Nastavování pinů");
|
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_RED_PIN, OUTPUT); Serial.println("Piny: 2/8");
|
||||||
pinMode(RGB_GREEN_PIN, OUTPUT); Serial.println("Piny: 3/8");
|
pinMode(RGB_GREEN_PIN, OUTPUT); Serial.println("Piny: 3/8");
|
||||||
pinMode(RGB_BLUE_PIN, OUTPUT); Serial.println("Piny: 4/8");
|
pinMode(RGB_BLUE_PIN, OUTPUT); Serial.println("Piny: 4/8");
|
||||||
@@ -229,6 +228,15 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
if (buttonPressed) {
|
||||||
|
if (millis() - buttonPressTime >= DEBOUNCE_MS) {
|
||||||
|
buttonPressed = false;
|
||||||
|
// handle the press
|
||||||
|
} else {
|
||||||
|
buttonPressed = false; // too fast, ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Serial.available()) {
|
if (Serial.available()) {
|
||||||
String cmd = Serial.readStringUntil('\n');
|
String cmd = Serial.readStringUntil('\n');
|
||||||
cmd.trim();
|
cmd.trim();
|
||||||
|
|||||||
Reference in New Issue
Block a user