Multiple LED's using an Array

hello! I am trying to turn on/off multiple LED's using an array function.

      const byte ledPins[] = {0, 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, A0, A1, A2, A3, A4, A5};
  int pinCount = 17;

  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    pinMode(ledPins[thisPin], OUTPUT);

  }
    //lights
    digitalWrite(ledPins[5,6,7],HIGH);
    delay(500);
    digitalWrite(ledPins[5,6,7],LOW);
    delay(500);
  
}

This just gets the last pin (pin 9, or "ledPins[7]") to flash. Am I supposed to use an & or something? I am going to end up building a sequence with 17 LED's and really wanted to be able to turn multiple on and off like this...

Hi,
What controller are you using?
It looks like you are using pin0 and pin1, they are the programming pins for the controller, which will cause erratic operation and make your controller hard to program.

What will you be using for a power suppply?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

ledPins[5,6,7]

That syntax is invalid.
You could use:

for(uint8_t i = 5; i <= 7; i++)
  digitalWrite (ledPins[i], HIGH);

Pieter

That syntax is invalid.
You could use:

for(uint8_t i = 5; i <= 7; i++)

digitalWrite (ledPins[i], HIGH);





Pieter

MY HERO XOXOXOXO

You already did it on the pinMode part. How did you figure it out there and not for the digitalWrite part?

ledPins[5,6,7]

That syntax is invalid

It is not invalid. It compiles. It runs and does something. Just not what the OP wanted. As the OP discovered, only the final led number is actioned. The reason is that the comma is actually an "operator" in C/C++. The expression "a, b" means "evaluate a but discard the result, then evaluate b and use that result". It may seem a little stupid that the compiler would allow that, but remember that even though the result a is discard, evaluating could have some useful side-effect. For example if you said "a++, b" then b would be used, but a would still have been incremented: next time you use a, you would see that a was one more than last time you used it.

Having said all that, I am not suggesting that anyone actually uses this technique. It's confusing and does not make your code easy to read or understand!