#include <FastLED.h>
#define NUM_LEDS 100
CRGB led1[NUM_LEDS];
CRGB led2[NUM_LEDS];
CRGB led3[NUM_LEDS];
CRGB led4[NUM_LEDS];
int time_gap = 500;
int r = 255;
int b = 0;
int g = 0;
void setup() {
FastLED.addLeds<WS2812B, 9, GRB>(led1, NUM_LEDS);
FastLED.addLeds<WS2812B, 10, GRB>(led2, NUM_LEDS);
FastLED.addLeds<WS2812B, 11, GRB>(led3, NUM_LEDS);
FastLED.addLeds<WS2812B, 12, GRB>(led4, NUM_LEDS);
FastLED.setBrightness(100);
}
int prevMillis = millis();
int currMillis = millis();
int i = 0, j = 0, k = 0, l = 0;
void loop() {
i = 0, j = 0, k = 0, l = 0;
while (l <= NUM_LEDS - 1) {
if (i < NUM_LEDS) led1[i++] = CRGB(r, g, b);
if (j < NUM_LEDS && currMillis - prevMillis >= time_gap)led2[j++] = CRGB(r, b, g);
if (k < NUM_LEDS && currMillis - prevMillis >= time_gap * 2)led3[k++] = CRGB(r, b, g);
if (l < NUM_LEDS && currMillis - prevMillis >= time_gap * 3) led4[l++] = CRGB(r, b, g);
FastLED.show();
delay(30);
currMillis = millis();
}
prevMillis = millis();
while (l > 0) {
if (i > 0)led1[--i] = CRGB(0, 0, 0);
if (j > 0 && currMillis - prevMillis >= time_gap)led2[--j] = CRGB(0, 0, 0);
if (k > 0 && currMillis - prevMillis >= time_gap * 2)led3[--k] = CRGB(0, 0, 0);
if (l > 0 && currMillis - prevMillis >= time_gap * 3)led4[--l] = CRGB(0, 0, 0);
FastLED.show();
delay(30);
currMillis = millis();
}
FastLED.clear();
prevMillis = millis();
}