add software debounce
This commit is contained in:
parent
8a001a4697
commit
5c3645d69d
1 changed files with 4 additions and 1 deletions
5
main.ino
5
main.ino
|
@ -225,6 +225,8 @@ class DisplayConfig {
|
||||||
|
|
||||||
|
|
||||||
unsigned long previousMillis = -1000000000;
|
unsigned long previousMillis = -1000000000;
|
||||||
|
unsigned long lastDebounceTime = 0;
|
||||||
|
unsigned long debounceDelay = 50;
|
||||||
bool buttonPressedLastCycle = false;
|
bool buttonPressedLastCycle = false;
|
||||||
bool sht3xErrorLastCycle = false;
|
bool sht3xErrorLastCycle = false;
|
||||||
|
|
||||||
|
@ -335,9 +337,10 @@ void loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (digitalRead(buttonPin)){
|
if (digitalRead(buttonPin)){
|
||||||
if (!buttonPressedLastCycle){
|
if (!buttonPressedLastCycle && millis() - lastDebounceTime > debounceDelay){
|
||||||
config->cycleScreen()->draw();
|
config->cycleScreen()->draw();
|
||||||
buttonPressedLastCycle = true;
|
buttonPressedLastCycle = true;
|
||||||
|
lastDebounceTime = millis();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buttonPressedLastCycle = false;
|
buttonPressedLastCycle = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue