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.

8th Dec 2016, 5:21 PM
mustafa arkin
mustafa arkin - avatar
2 Réponses
+ 1
after you increase i, you should make buttonState false.
11th Dec 2016, 4:48 PM
Dimitiko
+ 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)
3rd Jan 2017, 6:11 AM
seamiki
seamiki - avatar