Simple project help

I’m just starting off with my uno and started with a 9 LED’s or a breadboard. I am trying to go from pin 13-5 then 5-13 for a bounce back then as the layout is red:yellow:green:red:yellow:green:red:yellow:green i have it doing 13:10:7:12:9:6:11:8:5 so it goes all the reds then yellows then greens. Then I wanted to set a seed to do a random set 10 times before it starts the loop again. Simple stuff I guess. I’ll paste the code i have on the bottom but I was wondering how to set up a loop within the main void Loop (). I’m trying to do an if statement but it doesn’t seem to be working. Any advice or help would be appreciated.

void setup() {                
  pinMode(13, OUTPUT);    
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int counter;
  if (counter < 5) {
    counter++;
  digitalWrite(13, HIGH);   
  delay(50);              
  digitalWrite(13, LOW);        
  digitalWrite(12, HIGH);   
  delay(50);              
  digitalWrite(12, LOW);    
  digitalWrite(11, HIGH);   
  delay(50);              
  digitalWrite(11, LOW);     
  digitalWrite(10, HIGH);   
  delay(50);              
  digitalWrite(10, LOW);    
  digitalWrite(9, HIGH);   
  delay(50);              
  digitalWrite(9, LOW);    
  digitalWrite(8, HIGH);   
  delay(50);              
  digitalWrite(8, LOW);    
  digitalWrite(7, HIGH);   
  delay(50);              
  digitalWrite(7, LOW);    
  digitalWrite(6, HIGH);   
  delay(50);              
  digitalWrite(6, LOW);
  digitalWrite(5, HIGH);   
  delay(50);              
  digitalWrite(5, LOW);  
  
  digitalWrite(5, HIGH);   
  delay(50);              
  digitalWrite(5, LOW);        
  digitalWrite(6, HIGH);   
  delay(50);              
  digitalWrite(6, LOW);    
  digitalWrite(7, HIGH);   
  delay(50);              
  digitalWrite(7, LOW);     
  digitalWrite(8, HIGH);   
  delay(50);              
  digitalWrite(8, LOW);    
  digitalWrite(9, HIGH);   
  delay(50);              
  digitalWrite(9, LOW);    
  digitalWrite(10, HIGH);   
  delay(50);              
  digitalWrite(10, LOW);    
  digitalWrite(11, HIGH);   
  delay(50);              
  digitalWrite(11, LOW);    
  digitalWrite(12, HIGH);   
  delay(50);              
  digitalWrite(12, LOW);
  digitalWrite(13, HIGH);   
  delay(50);              
  digitalWrite(13, LOW);
  Serial.println(counter);
  }
  
  digitalWrite(13, HIGH);   
  delay(250);              
  digitalWrite(13, LOW);        
  digitalWrite(10, HIGH);   
  delay(250);              
  digitalWrite(10, LOW);    
  digitalWrite(7, HIGH);   
  delay(250);              
  digitalWrite(7, LOW);     
  digitalWrite(12, HIGH);   
  delay(250);              
  digitalWrite(12, LOW);    
  digitalWrite(9, HIGH);   
  delay(250);              
  digitalWrite(9, LOW);    
  digitalWrite(6, HIGH);   
  delay(250);              
  digitalWrite(6, LOW);    
  digitalWrite(11, HIGH);   
  delay(250);              
  digitalWrite(11, LOW);    
  digitalWrite(8, HIGH);   
  delay(250);              
  digitalWrite(8, LOW);
  digitalWrite(5, HIGH);   
  delay(250);              
  digitalWrite(5, LOW);
}

Learn how to do a for() loop. It will pay off huge on a project like this.

As an example (not what you wanted to do, but to give you an idea):

loop(){
  for (int i = 13; i>=5; i--){
    digitalWrite(i, HIGH);
    delay(100);
    digitalWrite(i, LOW);
  }

  for (int i = 5; i<=13; i++){
    digitalWrite(i, HIGH);
    delay(100);
    digitalWrite(i, LOW);
  }
}

Here is what I did finally. Also trying to get a small incandescent lamp working off the 3.3v connector. Trying to find a way to make it fade in and out too.

void setup() {   
  
  pinMode(13, OUTPUT);    
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  randomSeed(analogRead(0));
  Serial.begin(9600);
}

int counter = 0;
int rn = 0;
void loop() {
  
  digitalWrite(4, HIGH);
  
  if (counter < 5) {
    
  counter++;
    
  digitalWrite(13, HIGH);   
  delay(50);              
  digitalWrite(13, LOW);        
  digitalWrite(12, HIGH);   
  delay(50);              
  digitalWrite(12, LOW);    
  digitalWrite(11, HIGH);   
  delay(50);              
  digitalWrite(11, LOW);     
  digitalWrite(10, HIGH);   
  delay(50);              
  digitalWrite(10, LOW);    
  digitalWrite(9, HIGH);   
  delay(50);              
  digitalWrite(9, LOW);    
  digitalWrite(8, HIGH);   
  delay(50);              
  digitalWrite(8, LOW);    
  digitalWrite(7, HIGH);   
  delay(50);              
  digitalWrite(7, LOW);    
  digitalWrite(6, HIGH);   
  delay(50);              
  digitalWrite(6, LOW);
  digitalWrite(5, HIGH);   
  delay(50);              
  digitalWrite(5, LOW);  
  
  digitalWrite(5, HIGH);   
  delay(50);              
  digitalWrite(5, LOW);        
  digitalWrite(6, HIGH);   
  delay(50);              
  digitalWrite(6, LOW);    
  digitalWrite(7, HIGH);   
  delay(50);              
  digitalWrite(7, LOW);     
  digitalWrite(8, HIGH);   
  delay(50);              
  digitalWrite(8, LOW);    
  digitalWrite(9, HIGH);   
  delay(50);              
  digitalWrite(9, LOW);    
  digitalWrite(10, HIGH);   
  delay(50);              
  digitalWrite(10, LOW);    
  digitalWrite(11, HIGH);   
  delay(50);              
  digitalWrite(11, LOW);    
  digitalWrite(12, HIGH);   
  delay(50);              
  digitalWrite(12, LOW);
  digitalWrite(13, HIGH);   
  delay(50);              
  digitalWrite(13, LOW);
  Serial.println(counter);
  }
  
  if (counter >= 5 and counter <= 8) {
    
  counter++;
    
  digitalWrite(13, HIGH);   
  delay(200);              
  digitalWrite(13, LOW);        
  digitalWrite(10, HIGH);   
  delay(200);              
  digitalWrite(10, LOW);    
  digitalWrite(7, HIGH);   
  delay(200);              
  digitalWrite(7, LOW);     
  digitalWrite(12, HIGH);   
  delay(200);              
  digitalWrite(12, LOW);    
  digitalWrite(9, HIGH);   
  delay(200);              
  digitalWrite(9, LOW);    
  digitalWrite(6, HIGH);   
  delay(200);              
  digitalWrite(6, LOW);    
  digitalWrite(11, HIGH);   
  delay(200);              
  digitalWrite(11, LOW);    
  digitalWrite(8, HIGH);   
  delay(200);              
  digitalWrite(8, LOW);
  digitalWrite(5, HIGH);   
  delay(200);              
  digitalWrite(5, LOW);
  }
  
  if (counter >=8){
    counter++;
    rn = random(5,14);
  digitalWrite(rn, HIGH);   
  delay(20);              
  digitalWrite(rn, LOW);
  }
  
  if (counter > 1000){
  counter = 0;
  }
  
}

Here is what I did finally.

Does your code work satisfactory? Or are there still problems?

Also trying to get a small incandescent lamp working off the 3.3v connector. Trying to find a way to make it fade in and out too.

An easier way would be off a PWM pin (using a transistor as applicable). Something like analogWrite(pin, 168) will approximate 3.3V.