76Views4Replies

Author Options:

Arduino code help Answered

To the Instructables members,
      I'm trying to write a program that uses a pushbutton (momentary) to turn on and off LEDs.  I have two LEDs and one button.  Basically, I want to be able to push the button to switch LEDs.  One push - one LED turns on - another push - the second LED turns on - another push - the first LED turns on - and so on.  Anyone know how to do that?  I'm sure there's a simple solution that I've missed.  Any aid would be awesome.

Discussions

0
None
caitlinsdad

4 years ago

You need variables to keep track of whether tthe LED is lit up or not. Every time the switch is pressed, it checks to see if the first LED is lit, if not, light it up, if it is lit then turn that one off and light up the next one....

0
None
dudescaitlinsdad

Reply 4 years ago

Thanks, do you have a suggestion on how I would do that? I'm pretty much a noob :)

0
None
caitlinsdaddudes

Reply 4 years ago

1. Do you actually have an arduino to program and a switch, LEDs and a few resistors? If not, get the free Autodesk 123D Circuit Designer that has an arduino simulator so you can actually rig up your circuit and see it in action and troubleshoot from there.

2. Learn the basics

Light up an LED.

Light up two LEDs.

Use a switch as an input device to turn the LED on and off. Learn what it means to debounce a switch.

From there you can figure out how to switch on one LED or another.

3. I could tell you but you would learn nothing.

0
None
dudescaitlinsdad

Reply 4 years ago

Yeah, I have the Arduino and stuff (I'm actually somewhat experienced in electronics, just new to Arduion). I know how to denounce a pushbutton, and I think I've figured out how to do what I wanted originally. Thanks