2 LEDs, 2 Buttons, and a Big Problem

Hello,

I'm trying to operate 2 separate LEDs with 2 separate pushbutton switches. I wrote a code, and about halfway through, I tested it. The first button worked great -- push it once, light comes on. Push it again, light goes off.

Then, I wrote the code for the second LED/button. I essentially just duplicated the first half of the code with new variable names. But now, when I press either button, both lights come on. When I press either button again, both lights go off.

I want one button to control one light, and another button to control another light. Please help.

Please read this before adding any more posts.

Bob.

sydneyv513:
I want one button to control one light, and another button to control another light. Please help.

It's not clear what "help" you want.

You didn't post your own code, so nobody can help in the sense of having a look at it to see what's wrong.

Or are you asking for help in the sense of providing a working program? Seems most folk in this forum baulk at doing that (catch fish vs teach to fish debate), but I did write a quick sketch to do what you want, so if you want it, I will post it here in the forum.

Meantime you might like to look at the state change detect example in the IDE (File / Examples / Digital); but maybe that's what you did already, impossible to tell seeing as you didn't post your code so far.

If you ever want to go beyond 2 buttons and leds, or even if you only ever have 2, arrays will make things easier.

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images: