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);
}
}