Simple Array issues

I am having an issue, only pin 11 will work. Any suggestions would be appreciated! The Arduino is wired to an rgb amplifier but even if its removed I can only analogWrite or digitalWrite to the last pin in the array.

const int ledPin = {

9, 10, 11

};

const int pirPin = 3;

const long wait = 300000;

void setup()

{

pinMode (ledPin [0,1,2], OUTPUT);

pinMode (pirPin, INPUT);

digitalWrite (ledPin [0,1,2], LOW);

}

void loop()

{

if (digitalRead(pirPin)== HIGH)

{

analogWrite (ledPin [0,1,2], 200);

}

else

{

digitalWrite (ledPin [0,1,2], HIGH);

}

}

I don’t think you can do these:

pinMode (ledPin [0,1,2], OUTPUT);
digitalWrite (ledPin [0,1,2], LOW);
analogWrite (ledPin [0,1,2], 200);
digitalWrite (ledPin [0,1,2], HIGH);

Try this (in all the places where you access the array) instead :

for (int i = 0; i < 3; i++) {
  digitalWrite (ledPin[i], HIGH);
}

Of course for just 3 pins it’s just as easy to do it pin by pin.

digitalWrite (ledPin[0], HIGH);
digitalWrite (ledPin[1], HIGH);
digitalWrite (ledPin[2], HIGH);

Thank you very much! I will use the for loop. :slight_smile: