Help with Knight Rider Scanner lights?

I’m trying to get the knight rider scanner lights to work with for loops. Right now I’m doing it without them. But this would become ineffective when more LED’s are added. (Rights now only 7 LEDS. Connected through digital pins 2 to 8).

void setup()
{
  Serial.begin(9600);
  for(int i=2;i<=8;i++)
  {
  pinMode(i, OUTPUT);
  }
  Serial.println("Ready");
}

void loop()
{
  digitalWrite(5, HIGH);
   
  
  //frm centr to side (in)
  digitalWrite(6, HIGH);
  digitalWrite(4, HIGH);
  delay(200);
  digitalWrite(7, HIGH);
  digitalWrite(3, HIGH);
  delay(200);
  digitalWrite(8, HIGH);
  digitalWrite(2, HIGH);
  delay(500);
  
  //frm centr to side (dec)
  digitalWrite(6, LOW);
  digitalWrite(4, LOW);
  delay(200);
  digitalWrite(7, LOW);
  digitalWrite(3, LOW);
  delay(200);
  digitalWrite(8, LOW);
  digitalWrite(2, LOW);
  delay(500);
  
  //frm side to cen (in)
  digitalWrite(8, HIGH);
  digitalWrite(2, HIGH);
  delay(200);
  digitalWrite(7, HIGH);
  digitalWrite(3, HIGH);
  delay(200);
  digitalWrite(6, HIGH);
  digitalWrite(4, HIGH);
  delay(500);
  
  //frm side to cen (dec)
  digitalWrite(8, LOW);
  digitalWrite(2, LOW);
  delay(200);
  digitalWrite(7, LOW);
  digitalWrite(3, LOW);
  delay(200);
  digitalWrite(6, LOW);
  digitalWrite(4, LOW);
  delay(500);
}

with functions that contain for loops. Read the code before you try …

(code not tested, there might be some buguino’s in it :wink:

void setup()
{
  Serial.begin(9600);
  for(int i=2;i<=8;i++)
  {
    pinMode(i, OUTPUT);
  }
  Serial.println("Ready");
}

void loop()
{
  center2side(HIGH, 300); 
  delay(300);
  center2side(LOW, 150);
  delay(300);

  side2center(HIGH, 100);
  delay(300);
  side2center(LOW, 200);
  delay(300);
}

// mode = HIGH/LOW
// del = delay in milliesec.
void center2side(int mode, int del)
{
  for(int pin=5; pin<=8; pin++)
  {
      digitalWrite(pin, mode);
      digitalWrite(10-pin, mode);
      delay(del);
  }
}

// mode = HIGH/LOW
// del = delay in milliesec.
void side2center(int mode, int del)
{
  for(int pin=8; pin>=5; pin--)
  {
      digitalWrite(pin, mode);
      digitalWrite(10-pin, mode);
      delay(del);
  }
}

Wow, thnx alot.