RGB LEDS Strip

Hi guys,

I'm working on cleaning up my code on my RGB Strip. On this pattern, the colour goes up and then down, but I have created a long coding that could be done in much less code.
How do I input an array of colours instead of repeating the code for each different colour.
Many thanks!

void Stripe(){

   	// First slide the led in one direction
	for(int i = 0; i < NUM_LEDSUPPER; i++) {
		// Set the i'th led to red 
		ledsUPPER[i] = CRGB::Green;
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		//leds[i] = CRGB::Black;
		// Wait a little bit before we loop around and do it again
		delay(pause);
	}
	// Now go in the other direction.  
	for(int i = NUM_LEDSUPPER-1; i >= 0; i--) {
		// Set the i'th led to red 
		ledsUPPER[i] = CRGB::Green;
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		ledsUPPER[i] = CRGB::Black;
		// Wait a little bit before we loop around and do it again
		delay(pause);
        }
	for(int i = 0; i < NUM_LEDSUPPER; i++) {
		// Set the i'th led to red 
		ledsUPPER[i] = CRGB::Red;
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		//leds[i] = CRGB::Black;
		// Wait a little bit before we loop around and do it again
		delay(pause);
        }
         // Now go in the other direction.  
	for(int i = NUM_LEDSUPPER-1; i >= 0; i--) {
		// Set the i'th led to red 
		ledsUPPER[i] = CRGB::Red;
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		ledsUPPER[i] = CRGB::Black;
		// Wait a little bit before we loop around and do it again
		delay(pause);
	}
        for(int i = 0; i < NUM_LEDSUPPER; i++) {
		// Set the i'th led to red 
		ledsUPPER[i] = CRGB::Blue;
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		//leds[i] = CRGB::Black;
		// Wait a little bit before we loop around and do it again
		delay(pause);}
         // Now go in the other direction.  
	for(int i = NUM_LEDSUPPER-1; i >= 0; i--) {
		// Set the i'th led to red 
		ledsUPPER[i] = CRGB::Blue;
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		ledsUPPER[i] = CRGB::Black;
		// Wait a little bit before we loop around and do it again
		delay(pause);}
    for(int i = 0; i < NUM_LEDSUPPER; i++) {
		// Set the i'th led to red 
		ledsUPPER[i] = CRGB::Purple;
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		//leds[i] = CRGB::Black;
		// Wait a little bit before we loop around and do it again
		delay(pause);}
         // Now go in the other direction.  
	for(int i = NUM_LEDSUPPER-1; i >= 0; i--) {
		// Set the i'th led to red 
		ledsUPPER[i] = CRGB::Purple;
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		ledsUPPER[i] = CRGB::Black;
		// Wait a little bit before we loop around and do it again
		delay(pause);}
    for(int i = 0; i < NUM_LEDSUPPER; i++) {
		// Set the i'th led to red 
		ledsUPPER[i] = CRGB::Yellow;
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		//leds[i] = CRGB::Black;
		// Wait a little bit before we loop around and do it again
		delay(pause);}

         // Now go in the other direction.  
	for(int i = NUM_LEDSUPPER-1; i >= 0; i--) {
		// Set the i'th led to red 
		ledsUPPER[i] = CRGB::Yellow;
		// Show the leds
		FastLED.show();
		// now that we've shown the leds, reset the i'th led to black
		ledsUPPER[i] = CRGB::Black;
		// Wait a little bit before we loop around and do it again
		delay(pause);
        }
}

What's the CRGB class? Without providing all the code its often impossible to help
in any concrete way since declarations etc are missing, which are often crucial.

Yes, put the colours in an array, but how depends on the detail of these CRGB objects.

Thanks for replying Mark.
Here is the Code
The Main program is RGB_EX1 and Pulse and Stripe are components of that.

FastLED.h is a library referenced in that, but I do not know its role in the programme.

Any more questions, I'll be happy to answer

RGB_EX1.ino (3.11 KB)

Pulse.ino (2.22 KB)

Stripe.ino (4.83 KB)

FastLED.h (6.33 KB)