0
Is This Code Correct ? - Arduino C#
Hello I want to make someone press a button to his choice amount. Store that amount into an variable and use it in a loop, to make certain lights go on. This is what I have. if (reading != buttonState) { buttonState = reading; } if (buttonState == HIGH) { i++; } if (i == 1) digitalWrite(led2, HIGH); Im not sure if its good.
2 Réponses
+ 1
hint: use a boolean flag on input state change. don't forget button debouncing
store input staus
read input
if the read input differs from the stored input and is High (or Low according to how you wire your button)
debounce to avoid false triggers.
increase a counter variable that holds how many times the button was pressed
0
BTW i dont want it to jump to the first option when I click it once, does it wait until I click lets say 4 times? or does it now instantly choose option 1 when I dont want it to