I'm trying to do a simple state management using Attiny85 and Arduino Uno, my scenario is as follows.
-Counter starts from 0.
-Counter can go up to 3 at most.
-Certain functions are called according to the state of the counter.
void loop() {
btnState = digitalRead(button);
if (btnState != lastState) {
if (btnState == 1 && counter == 3) {
counter = 0;
lastState = btnState;
}
else {
counter++;
lastState = btnState;
}
delay(50);
}
if (btnState == 0) {
if (counter == 1) {
xyz();
}
if (counter == 2) {
abc();
}
if (counter == 3) {
asd();
}
}
}
With this code, once the button is pressed, the counter becomes 1, the function in the first state is called, but then the button becomes dysfunctional.