I want to use 2 LEDs and a pushbutton and program them in such that they have a sequence that the LEDs will go through. I am using an Arduino UNO. I have already model up the circuit in TinkerCAD.
Here is the sequence I want to get:
1st press:Only RED LED turn on
2nd press: Only GREEN LED turn on
3rd press: Both LED turn on
4th press: Both LED turn off
I'm not sure how to code it as I am quite new to Arduino and programming in general. Thank you in advance!
You keep track of which state your are in by using a variable - maybe call it 'state' and then every time you detect a button press. you increment 'state' and set the LEDs on/off. When it gets to the last state, it rolls over to 0.
I want to use 2 LEDs and a pushbutton and program them in such that they have a sequence that the LEDs will go through. I am using an Arduino UNO. I have already model up the circuit in TinkerCAD.
Here is the sequence I want to get:
1st press:Only RED LED turn on
2nd press: Only GREEN LED turn on
3rd press: Both LED turn on
4th press: Both LED turn off
I'm not sure how to code it as I am quite new to Arduino and programming in general. Thank you in advance!
Also since you are counting button presses make sure you check for a change in the button state and not the button state itself. Otherwise you will be very frustrated. The following tutorial will be very close to what you want to do: