Jag håller på med ett arduinoprojekt.
Det mesta fungerar nu som jag vill men när jag klickar på en knapp som ska få programmet att gå in i en meny så hoppar den in flera steg istället för ett, precis som om jag har klickat flera gånger på knappen.
Min fråga är:
Är det något fel på den här debounce koden som jag "stulit"

Jag är väldigt tacksam om någon vill ta sig tid och kolla på koden/hjälpa mig med detta.
/Magnus
Kod: Markera allt
//Läs av och debounce'a knappen
int reading = digitalRead(buttonPin); // read the state of the switch into a local variable:
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
if (reading != lastButtonState) { // If the switch changed, due to noise or pressing:
lastDebounceTime = millis(); // reset the debouncing timer
}
if ((millis() - lastDebounceTime) > debounceDelay) { // whatever the reading is at, it's been there for longer than the debounce delay, so take it as the actual current state
ButtonState = reading;
}
lastButtonState = reading; // save the reading. Next time through the loop,it'll be the lastButtonState:
//Debounce Klar