Please help with code

I put this code together from my small knowledge of the language and bits and pieces of others’ code. I keep getting errors when trying to upload. I think I may have a bracket or two in the wrong place. I commented where and what I want to do.

/*5 sets of leds fade randomly at random intensities for random durations. 
Leds fade back to 255 after random hold duration. I gave all the led sections 
different random numbers so they don't all fade the same. */


int led1Pin = 2;    
int led2Pin = 3;
int led3Pin = 4;
int led4Pin = 5;    
int led5Pin = 6;
int led6Pin = 7;
int led7Pin = 8;
int led8Pin = 9;

void setup(){}
void loop(){ 
  
  // I want the led sections to 
int randNumber1 = random(20, 255);
int randNumber2 = random(20, 255);
int randNumber3 = random(20, 255);
int randNumber4 = random(20, 255);
int randNumber5 = random(20, 255);
int randNumber6 = random(20, 255);
int randNumber7 = random(20, 255);

int randTime1 = random (2000, 5000);
int randTime2 = random (3000, 6000);


  for(int fadeValue1 = randNumber1 ; fadeValue1 <= 255; fadeValue1 -=5)   // fade in from random state to max (255) in increments of 5 points:
  for(int fadeValue2 = randNumber2 ; fadeValue2 <= 255; fadeValue2 -=5)   // fade in from random state to max (255) in increments of 5 points:
  for(int fadeValue3 = randNumber3 ; fadeValue3 <= 255; fadeValue3 -=5)   // fade in from random state to max (255) in increments of 5 points:
  for(int fadeValue4 = randNumber4 ; fadeValue4 <= 255; fadeValue4 -=5)   // fade in from random state to max (255) in increments of 5 points:
  for(int fadeValue5 = randNumber5 ; fadeValue5 <= 255; fadeValue5 -=5)   // fade in from random state to max (255) in increments of 5 points:
  for(int fadeValue6 = randNumber6 ; fadeValue6 <= 255; fadeValue6 -=5)   // fade in from random state to max (255) in increments of 5 points:
  for(int fadeValue7 = randNumber7 ; fadeValue7 <= 255; fadeValue7 -=5)   // fade in from random state to max (255) in increments of 5 points:
  {   
    analogWrite(ledPin1, fadeValue1);
    analogWrite(ledPin2, fadeValue2);
    analogWrite(ledPin3, fadeValue3);
    analogWrite(ledPin4, fadeValue4);
    analogWrite(ledPin5, fadeValue5);
    analogWrite(ledPin6, fadeValue6);
    analogWrite(ledPin7, fadeValue7);

delay (randTime1);  // control fade duration
}

delay (randTime2); //hold dimmed state for a random time

// here I would like to fade up to 255 from the led's current state

  for(int fadeValue1 = randNumber1 ; fadeValue1 <= 255; fadeValue1 +=5)   // fade in from random state to max (255) in increments of 5 points:
  for(int fadeValue2 = randNumber2 ; fadeValue2 <= 255; fadeValue2 +=5)   // fade in from random state to max (255) in increments of 5 points:
  for(int fadeValue3 = randNumber3 ; fadeValue3 <= 255; fadeValue3 +=5)   // fade in from random state to max (255) in increments of 5 points:
  for(int fadeValue4 = randNumber4 ; fadeValue4 <= 255; fadeValue4 +=5)   // fade in from random state to max (255) in increments of 5 points:
  for(int fadeValue5 = randNumber5 ; fadeValue5 <= 255; fadeValue5 +=5)   // fade in from random state to max (255) in increments of 5 points:
  for(int fadeValue6 = randNumber6 ; fadeValue6 <= 255; fadeValue6 +=5)   // fade in from random state to max (255) in increments of 5 points:
  for(int fadeValue7 = randNumber7 ; fadeValue7 <= 255; fadeValue7 +=5)   // fade in from random state to max (255) in increments of 5 points:
  {   
    analogWrite(ledPin1, fadeValue1);
    analogWrite(ledPin2, fadeValue2);
    analogWrite(ledPin3, fadeValue3);
    analogWrite(ledPin4, fadeValue4);
    analogWrite(ledPin5, fadeValue5);
    analogWrite(ledPin6, fadeValue6);
    analogWrite(ledPin7, fadeValue7);

    delay(randTime1);     // wait for fadeDelay milliseconds to see the dimming effect
  }


delay (10000); //delay 10 seconds before allowing clouds to run again
 

}

My other question is about creating a function from the above code. I think creating a function is what i need to do but I don’t know how to do it evidently. Would it simply be something like:

void setClouds {
all code 
}

and then just call for it when needed.
What all of my code would I include in the function and how would I call for it?

Here is where I would want to insert “setClouds” It is a piece of a larger sketch I am working on still.

void setLed(int mins,    // current time in minutes
            int ledPin,  // pin for this channel of LEDs
            int start,   // start time for this channel of LEDs
            int period,  // photoperiod for this channel of LEDs
            int fade,    // fade duration for this channel of LEDs
            int ledMax   // max value for this channel
            )  {
  if (mins > start && mins <= start + fade)  {
    analogWrite(ledPin, map(mins - start, 0, fade, 0, ledMax));
  }
    if (mins > start + period && mins <= start + period - fade)  {
    // *!!!Insert setClouds here!!!!*
  }
    if (mins > start + period - fade && mins <= start + period)  {
    analogWrite(ledPin, map(mins - start + period - fade, 0, fade, ledMax, 0));
  }
}

Thank you for reading this and being patient with me, I’m trying to learn as I go.

"ledPin1" is not the same as "led1Pin". Naming must be consistent.

Can I suggest some background reading about arrays?

Also looking at for loops as your loops :-

for (…) {
for (…) {

}
}

you where missing the {} surrounding the code

You have also declared variables led1Pin and used ledPin1 in your code!!!
The other problem you have is the code will only write to PWM pins which on my dumilinove are 3,5,6,9,10,11!!!

/*5 sets of leds fade randomly at random intensities for random durations.
 Leds fade back to 255 after random hold duration. I gave all the led sections
 different random numbers so they don't all fade the same. */


int ledPin1 = 2;    
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 5;    
int ledPin5 = 6;
int ledPin6 = 7;
int ledPin7 = 8;
int ledPin8 = 9;

void setup(){
}
void loop(){

     // I want the led sections to
     int randNumber1 = random(20, 255);
     int randNumber2 = random(20, 255);
     int randNumber3 = random(20, 255);
     int randNumber4 = random(20, 255);
     int randNumber5 = random(20, 255);
     int randNumber6 = random(20, 255);
     int randNumber7 = random(20, 255);

     int randTime1 = random (2000, 5000);
     int randTime2 = random (3000, 6000);


     for(int fadeValue1 = randNumber1 ; fadeValue1 <= 255; fadeValue1 -=5){   // fade in from random state to max (255) in increments of 5 points:
          for(int fadeValue2 = randNumber2 ; fadeValue2 <= 255; fadeValue2 -=5) {  // fade in from random state to max (255) in increments of 5 points:
               for(int fadeValue3 = randNumber3 ; fadeValue3 <= 255; fadeValue3 -=5) {  // fade in from random state to max (255) in increments of 5 points:
                    for(int fadeValue4 = randNumber4 ; fadeValue4 <= 255; fadeValue4 -=5) {  // fade in from random state to max (255) in increments of 5 points:
                         for(int fadeValue5 = randNumber5 ; fadeValue5 <= 255; fadeValue5 -=5) {  // fade in from random state to max (255) in increments of 5 points:
                              for(int fadeValue6 = randNumber6 ; fadeValue6 <= 255; fadeValue6 -=5) {  // fade in from random state to max (255) in increments of 5 points:
                                   for(int fadeValue7 = randNumber7 ; fadeValue7 <= 255; fadeValue7 -=5)   // fade in from random state to max (255) in increments of 5 points:
                                   {  
                                        analogWrite(ledPin1, fadeValue1);
                                        analogWrite(ledPin2, fadeValue2);
                                        analogWrite(ledPin3, fadeValue3);
                                        analogWrite(ledPin4, fadeValue4);
                                        analogWrite(ledPin5, fadeValue5);
                                        analogWrite(ledPin6, fadeValue6);
                                        analogWrite(ledPin7, fadeValue7);
                                        delay (randTime1);  // control fade duration
                                   }
                              }
                         }
                    }
               }
          }
     }
     delay (randTime2); //hold dimmed state for a random time

     // here I would like to fade up to 255 from the led's current state

     for(int fadeValue1 = randNumber1 ; fadeValue1 <= 255; fadeValue1 +=5) {  // fade in from random state to max (255) in increments of 5 points:
          for(int fadeValue2 = randNumber2 ; fadeValue2 <= 255; fadeValue2 +=5){   // fade in from random state to max (255) in increments of 5 points:
               for(int fadeValue3 = randNumber3 ; fadeValue3 <= 255; fadeValue3 +=5){   // fade in from random state to max (255) in increments of 5 points:
                    for(int fadeValue4 = randNumber4 ; fadeValue4 <= 255; fadeValue4 +=5){   // fade in from random state to max (255) in increments of 5 points:
                         for(int fadeValue5 = randNumber5 ; fadeValue5 <= 255; fadeValue5 +=5) {  // fade in from random state to max (255) in increments of 5 points:
                              for(int fadeValue6 = randNumber6 ; fadeValue6 <= 255; fadeValue6 +=5){   // fade in from random state to max (255) in increments of 5 points:
                                   for(int fadeValue7 = randNumber7 ; fadeValue7 <= 255; fadeValue7 +=5)   // fade in from random state to max (255) in increments of 5 points:
                                   {  
                                        analogWrite(ledPin1, fadeValue1);
                                        analogWrite(ledPin2, fadeValue2);
                                        analogWrite(ledPin3, fadeValue3);
                                        analogWrite(ledPin4, fadeValue4);
                                        analogWrite(ledPin5, fadeValue5);
                                        analogWrite(ledPin6, fadeValue6);
                                        analogWrite(ledPin7, fadeValue7);

                                        delay(randTime1);     // wait for fadeDelay milliseconds to see the dimming effect
                                   }
                              }
                         }
                    }
               }
          }
     }

     delay (10000); //delay 10 seconds before allowing clouds to run again


}

Ahhh didn't catch that naming mistake!

Thank you for the responses and the code work, I will give the changes a try later tonight.

I should have specified before that I am using the Arduino Mega

Any tips for wrapping all of that into a function? Or is a function what I need?

Thanks all!