Help with program

i have 2 buttons and it seems that the program always assigns everythign to button one, please help const int button = 2; const int button2 = 5; int led = 13; int led2 = 12; int led3 = 11; int led4 = 10; int led5 = 9; int state = 0; //variable for button int set = 0;

void setup() { // put your setup code here, to run once: pinMode(led, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(led5, OUTPUT); pinMode(button, INPUT); pinMode(button2, INPUT); }

void loop() { // put your main code here, to run repeatedly:

state = digitalRead(button); set = digitalRead(button2);

if (state == HIGH){ digitalWrite(led, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, LOW); digitalWrite(led5, LOW); }

else (set == LOW); digitalWrite(led,LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); digitalWrite(led5, LOW);

}

else (set == LOW);

else doesn't get a condition.

IF state is HIGH, how does that prove that set is LOW? They're two different pins. What if both pins were HIGH?

To amplify what Delta_G is saying, you probably need:

if (state == HIGH)
{
    if (set == HIGH)
    {
       //Do state is HIGH and set is HIGH stuff here
    } else {
      // Do state is HIGH and set is LOW stuff here
    }
} else {
    if (set ==HIGH)
    {
      // Do state is LOW and set is HIGH stuff here
    } else {
      // Do state is LOW and set is LOW stuff here
    }
}

First: please put your code in code tags. It's the hash-mark button in the editor (#). My comments below:

const int button = 2;
const int button2 = 5;
int led = 13;
int led2 = 12;
int led3 = 11;
int led4 = 10;
int led5 = 9;
int state = 0; //variable for button
int set = 0;

This doesn't directly relate to your question, but in general, you will do well to give your variables much more descriptive names. Button and Button2 doesn't tell you or anybody else anything useful about what the button does, which button it is, and so forth. As your programs get more complex, and as you involve more people in helping you write and debug them, this will become critical. A lot of people will look at these variable names and just pass on by because they don't want to take the effort of, basically, trying to read your mind.

pinMode(button, INPUT);
pinMode(button2, INPUT);

Are you using external pull-down resistors for your buttons? If not, your program is not going to work right. The Arduino has built-in pull-up resistors, which are generally preferable to use, because they simplify the wiring. To use the internal pullup resistors, first use pinMode(pinNum, INPUT_PULLUP). Second, wire your button like this: DIGITAL PIN -> BUTTON -> GROUND. Third, when you read the pin, the pin will be HIGH when the button is not-pressed and LOW when the button is pressed. This is opposite from how it works with pull-down resistors.

if (state == HIGH){
  // something
 }
 else (set == LOW);
digitalWrite(led,LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
 }

This construct compiles, but it is not doing what you want. Perhaps you mean:

if (state == HIGH) {
  // do something
} else if (set == LOW) {
  // do something else
}

In other words, I think you forgot the "if" after the "else". Your code actually works out like this:

if (state == HIGH){
  // something
}
else  // gets run if state != HIGH
{
  (set == LOW); // evaluates to either TRUE or FALSE, but doesn't actually do anything--basically a No-op
}

// These always occur, regardless of button state
digitalWrite(led,LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
 }

As was pointed out in a prior comment, you need to be careful about your boolean checks. You have covered the case where state is un-pressed and where set is pressed, but what about the case where they are both pressed or state is pressed and set is un-pressed, etc... your program logic needs to account for all possible input states or you may end up in an undefined situation and the program won't work like you want it to.