Arduino toggle button

So this is the code I made A toggle button with. So when I press the button, the counter stays on 1 and when i press again it goes to 0. But Im actually not sure how this works exactly, I cant bring my self to understand, could somebody smart kinda explain the process here? if(buttonState==HIGH && oldButtonState==LOW) { counter++; } if(counter>1) {counter=0;} oldButtonState=buttonState; } thanks!
6 Replies
MaderDash
MaderDash2mo ago
Ok so its a lock out. You can NOT get into the first if statment. Unless the seccone one was the last one to take place. And same with the seccond one. @TheStudier
TheStudier
TheStudierOP2mo ago
hmm
MaderDash
MaderDash2mo ago
Its kinda incomplete but that's the premise
TheStudier
TheStudierOP2mo ago
okay thanks Ill try to figure it out so when I press the button and keep it pressed, shouldn't the counter just grow a lot why does it stay at 1
MaderDash
MaderDash2mo ago
Because it cant If its over 1 its set back to 0
TheStudier
TheStudierOP2mo ago
true

Did you find this page helpful?