Multiple LED's blink without delay

I have an array of 11 pins. I am trying to get a sequence going where the LEDs blink on and off from the outside in to the middle.

0 - - - - - - - - - 0

  • 0 - - - - - - - 0 -
    • 0 - - - - - 0 - -
      • 0 - - - 0 - - -
        • 0 - 0 - - - -
          • 0 - - - - -

0 = LED on.

I can do this with delays by coding the individual pins manually.

I have been using the blink without delay example.
The problem I am having is the LED board I am using is inverted
So HIGH for the LED’s off and LOW for the LED’s on.

The problem is every second LED is turning on one at a time and not blinking. Once these are all on, the other LED’s start blinking. It does not seem to be incrementing through my arrays 1 pin at a time.

My code is:

int index = 0;
int ledPins[] = {
  9,8,7,6,5,4,3,2,14,15,16};

int ledState = HIGH;

unsigned long currentMillis = millis();
unsigned long previousMillis = millis();
long interval = 1000;

int x = 0;
int test1L[] = {
  9,8,7,6,5};
int test1R[] = {
  16,15,14,2,3}; 

void setup()
{
  Serial.begin(19200);

  for(index = 0; index < 11; index++)
  {
    pinMode(ledPins[index], OUTPUT);
  }
  for(int i = 0; i < 11; i++)
  {
    digitalWrite(ledPins[i], HIGH);
  }
}

void loop()
{  
  unsigned long currentMillis = millis();

  analogWrite(11, 0);
  analogWrite(12, 0);
  analogWrite(13, 255);
  
  if(currentMillis - previousMillis > interval) 
  {
    previousMillis = currentMillis;
    
    if (ledState == HIGH) 
    {
      ledState = LOW;
    }
    else 
    {
      ledState = HIGH; 
    } 
    analogWrite(11, 0);
    analogWrite(12, 0);
    analogWrite(13, 255);

    digitalWrite(test1L[x], ledState);
    digitalWrite(test1R[x], ledState);

    x++; //increment x pins
  }
  if(x > 4)
  {
    digitalWrite(4, ledState); //blink middle LED 
    x = 0;
  }  
}

simplified the code a bit, find the 7 differences :wink:

int ledPins[] = {
  9,8,7,6,5,4,3,2,14,15,16};

unsigned long previousMillis = 0;
unsigned long interval = 1000;

int x = 0;

void setup()
{
  Serial.begin(19200);

  for(int i= 0; i < 11; i++)
  {
    pinMode(ledPins[i], OUTPUT);
    digitalWrite(ledPins[i], HIGH);
  }
}

void loop()
{  
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) 
  {
    previousMillis = currentMillis;
    
    // switch OFF
    digitalWrite(ledPins[x], HIGH);       // left
    digitalWrite(ledPins[9-x], HIGH);  // right

     x++;
     if (x == 4) x = 0;

    // switch ON
    digitalWrite(ledPins[x], LOW);       // left
    digitalWrite(ledPins[9-x], LOW);  // right

    digitalWrite(4, !digitalRead(4));  //invert middle LED every step

  }
}