Is This Code Correct ? - Arduino C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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.

8th Dec 2016, 5:01 PM
mustafa arkin
mustafa arkin - avatar
2 Answers
+ 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
3rd Jan 2017, 6:12 AM
seamiki
seamiki - avatar
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
8th Dec 2016, 5:14 PM
mustafa arkin
mustafa arkin - avatar