# problem with my code

can someone help me with my code? i’m a beginner to this and i’m having a hard time finding out what the problem is i want to make it so that when the push button is pressed all the LEDS turn on it says “invalid conversion from ‘int*’ to ‘unit8’” here’s my code

int button1Pin = 12; // pushbutton 1 pin
int button2Pin = -11; // pushbutton 2 pin
int ledPins = {2,3,4,5,6,7,8,9}; // Defines an array to store the pin numbers of the 8 LEDs.
int button1State, button2State; // variables to hold the pushbutton states

void setup()
{
// setup all 8 pins as OUTPUT - notice that the list is “indexed” with a base of 0.
pinMode(ledPins,OUTPUT); // ledPins = 2
pinMode(ledPins,OUTPUT); // ledPins = 3
pinMode(ledPins,OUTPUT); // ledPins = 4
pinMode(ledPins,OUTPUT); // ledPins = 5
pinMode(ledPins,OUTPUT); // ledPins = 6
pinMode(ledPins,OUTPUT); // ledPins = 7
pinMode(ledPins,OUTPUT); // ledPins = 8
pinMode(ledPins,OUTPUT); // ledPins = 9

// Set up the pushbutton pins to be an input:
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
}

void loop()
{

// if button1 or button 2 are pressed (but not both)
if (((button1State == LOW) && (button2State == HIGH)) || ((button1State == HIGH) && (button2State == LOW)))
{
digitalWrite(ledPins, HIGH); // turn the LED on
}
else
{
digitalWrite(ledPins, LOW); // turn the LED off
}
}

I see two things. First is button2Pin really suppose to be -11 instead of 11?

Second, the digitalWrite will not take the array to the best of my knowledge. You can add a loop to write the pins one at a time

``````digitalWrite(ledPins[i] ...
``````

Please use code tags in future.
`** **[code]** **`
`** **[/code]** **`
will result in

`````` int button1Pin = 12;  // pushbutton 1 pin
int button2Pin = -11;  // pushbutton 2 pin
int ledPins[] = {2,3,4,5,6,7,8,9};   // Defines an array to store the pin numbers of the 8 LEDs.
int button1State, button2State;  // variables to hold the pushbutton states

void setup()
{
// setup all 8 pins as OUTPUT - notice that the list is "indexed" with a base of 0.
pinMode(ledPins,OUTPUT);  // ledPins = 2
pinMode(ledPins,OUTPUT);  // ledPins = 3
pinMode(ledPins,OUTPUT);  // ledPins = 4
pinMode(ledPins,OUTPUT);  // ledPins = 5
pinMode(ledPins,OUTPUT);  // ledPins = 6
pinMode(ledPins,OUTPUT);  // ledPins = 7
pinMode(ledPins,OUTPUT);  // ledPins = 8
pinMode(ledPins,OUTPUT);  // ledPins = 9

// Set up the pushbutton pins to be an input:
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
}

void loop()
{

// if button1 or button 2 are pressed (but not both)
if (((button1State == LOW) && (button2State == HIGH)) || ((button1State == HIGH) && (button2State == LOW)))
{
digitalWrite(ledPins, HIGH);  // turn the LED on
}
else
{
digitalWrite(ledPins, LOW);  // turn the LED off
}
}
``````

ledPins is an array of integers; digitalWrite expects a single integer. So you have to loop through the array.

In setup(), you can optimize your code a bit (your current code is not wrong!)

``````  for (int cnt = 0; cnt < 8; cnt++)
{
pinMode(ledPins[cnt], OUTPUT);
}
``````

and in the problematic code (e.g. where you set the pins HIGH)

``````  for (int cnt = 0; cnt < 8; cnt++)
{
digitalWrite(ledPins[cnt], HIGH);
}
``````