How to light up multiple LED's in an array?

Im just starting with Arduino and need some help.

I have made an array where i declare the pins that are attached to an LED. Now i try to get some effects from the LED's like blinking a random LED, the nightrider effect and so on.

There is one effect i like to accomplish but i don't know how. I wanna light up the LED's of pin 6 and 13 simultaneously, next i wanna light up 7 and 12, than 8 and 11 and finally 9 and 10.

I made two for loops each of them split the array in half but of course they can't start at the same time. Do you know the right way on how to accomplish this effect?

int timer = 500;
int ledPins[] = { 6, 7, 8, 9, 10, 11, 12, 13 };

void setup() {
  for (int i = 0; i < sizeof(ledPins)/sizeof(ledPins[0]); i++) {
    pinMode(ledPins[i], OUTPUT);
  }
}

void loop() {
 for (int i = 0; i < sizeof(ledPins)/sizeof(ledPins[0])/2; i++) {
    digitalWrite(ledPins[i], HIGH);
    delay(timer);
    digitalWrite(ledPins[i], LOW);
  }

  for (int i = sizeof(ledPins)/sizeof(ledPins[0]) - 1; i >= sizeof(ledPins)/sizeof(ledPins[0])/2; i--) {
    digitalWrite(ledPins[i], HIGH);
    delay(timer);
    digitalWrite(ledPins[i], LOW);
  }
}

Any help will be appreciated :slight_smile:

The pins you want to light up are in ledPins. If you want the effect to cross over in the middle, the loop has to be for the entire array. If you want to stop in the middle, only half.

Then something like this

for (i=0; i<max; i++)
{
  digitalWrite(ledPins[i],HIGH);
  digitalWrite(ledPins[ARRAY_SIZE(ledPins)-1-i], HIGH);
  delay();
  // digitalwrite(LOW) for same pins
}

Thanks! I got it to work :slight_smile: