#include <FastLED.h>
#define LED_PIN 13
#define NUM_LEDS 60 // Adjust to the number of LEDs in your strip
#define BRIGHTNESS 200
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
bool coloredPositions[NUM_LEDS]; // Array to track the positions of colored LEDs
CRGB coloredColors[NUM_LEDS]; // Array to store the random colors for colored LEDs
void setup() {
Serial.begin(115200);
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
memset(coloredPositions, 0, sizeof(coloredPositions)); // Initialize all positions to false
// Clear the strip
fill_solid(leds, NUM_LEDS, CRGB::Black);
// Update the LED strip
FastLED.show();
}
void loop() {
led();
}
void led() {
static uint8_t offset = 0; // Offset for the moving red pattern
// Clear the strip
fill_solid(leds, NUM_LEDS, CRGB::Black);
// Set every other LED to a dimming and color-changing red with an offset
for (int i = 0; i < NUM_LEDS; i++) {
if ((i + offset) % 2 == 0) {
uint8_t brightness = BRIGHTNESS * (NUM_LEDS - i) / NUM_LEDS;
uint8_t red = 255;
uint8_t green = 255 * i / NUM_LEDS; // Increase green to make the color yellower as it travels down
leds[i] = CRGB(red, green, 0);
leds[i].fadeLightBy(255 - brightness);
}
}
// Move the colored LEDs down the strip with fading
for (int i = NUM_LEDS - 1; i > 0; i--) {
coloredPositions[i] = coloredPositions[i - 1];
coloredColors[i] = coloredColors[i - 1];
if (coloredPositions[i]) {
uint8_t brightness = BRIGHTNESS * (NUM_LEDS - i) / NUM_LEDS;
leds[i] = coloredColors[i];
leds[i].fadeLightBy(255 - brightness);
}
}
coloredPositions[0] = false; // Reset the first position
// Frequently add a new random colored runner
if (random(0, 4) > 2) { // Increased frequency here
coloredPositions[0] = true;
// Generate a random reddish color with less yellow
uint8_t red = random(128, 256); // Red component between 128 and 255
uint8_t green = random(0, 64); // Green component between 0 and 63 for less yellow
coloredColors[0] = CRGB(red, green, 0);
}
// Show the LEDs
FastLED.show();
// Increment the offset to create the moving effect
offset++;
// Wrap around the offset
if (offset >= 2) {
offset = 0;
}
// Control the speed of the effect
delay(10); // Adjust delay for speed control
}