Go Down

Topic: 2 LEDs, 2 Buttons, and a Big Problem (Read 388 times) previous topic - next topic

sydneyv513

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.

ballscrewbob

It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

anthonyHope

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.




larryd

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: 
https://forum.arduino.cc/index.php?topic=519037.0



No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Go Up