0
Does The Execution Of The Code Wait For The Input?
if (reading != buttonState) { buttonState = reading; } if (buttonState == HIGH) { i++; } if (i == 1) digitalWrite(led2, HIGH); if (i==4) (do something) Hello this is my code. I want someone to press a button lets say 4 times, will the code if 1 get executed instantly before someone presses a button 4 times ? This is arduino btw.
2 ответов
+ 1
after you increase i, you should make buttonState false.
+ 1
the code as it is written will probably do this:
upon pressing the button, the loop will run 4 times in a few milliseconds increeasing I every time and continue as you pressed the button 4 times. Use a boolean flag to detect change state of the button. Don't forget debouncing the input. Tons of tutorials on line (see morse decoders for example)