Help with 6 button, 6 led code

Hey everyone, so I am trying to program and wire up 6 leds to 6 different button. So if you push button 1, led 1 lights, button 2 lights led 2 and so on. Here is the code that I am using, can anyone see what I am doing wrong?

// constants won't change. They're used here to // set pin numbers: const int buttonPin1 = 2; // the number of the pushbutton pin const int buttonPin2 = 3; const int buttonPin3 = 4; const int buttonPin4 = 5; const int buttonPin5 = 6; const int buttonPin6 = 7; const int ledPin1 = 13; const int ledPin2 = 12; const int ledPin3 = 11; const int ledPin4 = 10; const int ledPin5 = 9; const int ledPin6 = 8;

// variables will change: int buttonState = 0; // variable for reading the pushbutton status

void setup() { // initialize the LED pin as an output: pinMode(ledPin1, OUTPUT); // initialize the LED pin as an output: pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(ledPin4, OUTPUT); pinMode(ledPin5, OUTPUT); pinMode(ledPin6, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin1, INPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin2, INPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin3, INPUT); pinMode(buttonPin4, INPUT); pinMode(buttonPin5, INPUT); pinMode(buttonPin6, INPUT); }

void loop(){ // read the state of the pushbutton value: buttonState = digitalRead(buttonPin1); // read the state of the pushbutton value: buttonState = digitalRead(buttonPin2); buttonState = digitalRead(buttonPin3); buttonState = digitalRead(buttonPin4); buttonState = digitalRead(buttonPin5); buttonState = digitalRead(buttonPin6);

// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, HIGH); digitalWrite(ledPin3, HIGH); digitalWrite(ledPin4, HIGH); digitalWrite(ledPin5, HIGH); digitalWrite(ledPin6, HIGH); } else { // turn LED off: digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); digitalWrite(ledPin4, LOW); digitalWrite(ledPin5, LOW); digitalWrite(ledPin6, LOW);

if (digitalRead(buttonPin1) == HIGH) digitalWrite(ledPin1, 100); digitalWrite (ledPin2, 0); digitalWrite(ledPin3, 0); digitalWrite(ledPin4, 0); digitalWrite(ledPin5, 0); digitalWrite(ledPin6, 0);

if (digitalRead(buttonPin2) == HIGH) digitalWrite(ledPin1, 0); digitalWrite(ledPin2, 100); digitalWrite(ledPin3, 0); digitalWrite(ledPin4, 0); digitalWrite(ledPin5, 0); digitalWrite(ledPin6, 0);

if (digitalRead(buttonPin3) == HIGH) digitalWrite(ledPin1, 0); digitalWrite(ledPin2, 0); digitalWrite(ledPin3, 100); digitalWrite(ledPin4, 0); digitalWrite(ledPin5, 0); digitalWrite(ledPin6, 0);

if (digitalRead(buttonPin4) == HIGH) digitalWrite(ledPin1, 0); digitalWrite(ledPin2, 0); digitalWrite(ledPin3, 0); digitalWrite(ledPin4, 100); digitalWrite(ledPin5, 0); digitalWrite(ledPin6, 0);

if (digitalRead(buttonPin5) == HIGH) digitalWrite(ledPin1, 0); digitalWrite(ledPin2, 0); digitalWrite(ledPin3, 0); digitalWrite(ledPin4, 0); digitalWrite(ledPin5, 100); digitalWrite(ledPin6, 0);

if (digitalRead(buttonPin6) == HIGH) digitalWrite(ledPin1, 0); digitalWrite(ledPin2, 0); digitalWrite(ledPin3, 0); digitalWrite(ledPin4, 0); digitalWrite(ledPin5, 0); digitalWrite(ledPin6, 100); } }

I can tell you some things you've been doing wrong:

1st. You didn't read the instructions on how to use the forum. So: 2nd. You didn't put your code in code tags. 3rd. You didn't tell us how you connected the buttons to your Arduino. 4th. You didn't tell us what makes you think something is wrong. 5th. (perhaps) You didn't use the option to enable pull up of button pins (see 3rd.) 6th. You are looking for a signal to get HIGH.Do you know for sure it is getting LOW at any time ? 7th. (big one !) You are setting buttonState to each button, and the last one you read will be left after reading them all. Then you are either switching all LEDs on or off. After that you are switching each separate LED on if buttonState is HIGH, and off again after the next LED is to be switched on (and it will). This all happens in less than 1/1000 of a second or so (moderate guess). All LEDs will be lit slightly, certainly not at full brightness to your eyes, if you can see any light emitted.

Make sure you understand how fast things happens in Arduino world. buttonState is there to help you see some button has been pressed for some time, and to help prevent registering false button pushes. Read about debounce again, more carefully, you left out something. Your code can be optimized big time by counting a bit. And using calculations you can also register multiple button presses if you like (but your sketch doesn't show you want that at this moment).

Do not try to solve all these in one go. Take it step by step.

One of your 'if (buttonState == HIGH) {' has the curly brackets after it, the others don't. I think you meant to have them on each section.

You would be much better deleting all but one button and one led, get that working, then introduce subsequent items line by line without breaking the original function. ('step by step' as previously said).

You don't need "== HIGH", 'if (buttonState) is sufficient. Its zero or something.