Need help with Arduino

My code is not successful and I am having a hard time understanding why

I need the following conditions to be satisfied. There are 4 lights and two buttons

If you press button 1- light 3 comes on
If you press button 2- light 2 comes on
If you press both buttons - light 4 comes on
If none are pressed- light 1 comes on

As of right now when the code is ran, light 1 comes on and stays on no matter if I press the buttons or not

Code.txt (610 Bytes)

You can remove these lines, they do absolutely nothing except compare the variables to zero, and then discard the result:

 But1 == 0;
  But2 == 0;

Also there is no wire connecting one of your buttons to the Arduino.

The first button on the left isn't connected to an Arduino pin. I'm not sure why you have But1 == 0 and But2 == 0 in your program?

You need to think of the buttons as existing in states. You first want to check if no buttons are pressed. It should look something like this:

If both buttons are not pressed then
...do "neither button is pressed"
Else // this else means that one of the buttons is pressed
...If Button1 is pressed then
......If Button2 is pressed then
.........do "both buttons are pressed"
......Else // this else means that Button1 is pressed but not Button2
.........do "only Button1 is pressed"
......End If
...Else // this else means that Button1 is not pressed, and that one of the buttons is pressed (so, Button2)
......do "only Button2 is pressed"
.....End If
End If

Be careful with your braces {}.

Hi,

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile: