#include "FastLED.h"
// Number of LED segments and their size
#define NUM_SEGMENTS 3
#define SEGMENT_SIZE 8
// The data pins connected to the LED segments
const uint8_t dataPins[NUM_SEGMENTS] = {6, 5, 4};
// Define the arrays of LEDs for each segment
CRGB leds1[SEGMENT_SIZE];
CRGB leds2[SEGMENT_SIZE];
CRGB leds3[SEGMENT_SIZE];
// Array of pointers to the LED arrays
CRGB *ledArrays[NUM_SEGMENTS] = {leds1, leds2, leds3};
// Define colors
const CRGB colors[] = {CRGB::White, CRGB::Yellow, CRGB::Green, CRGB::Cyan, CRGB::Blue, CRGB::Magenta, CRGB::Red, CRGB::Orange};
void setup() {
// Initialize the FastLED library for each segment
FastLED.addLeds<WS2812, 6, GRB>(leds1, SEGMENT_SIZE);
FastLED.addLeds<WS2812, 5, GRB>(leds2, SEGMENT_SIZE);
FastLED.addLeds<WS2812, 4, GRB>(leds3, SEGMENT_SIZE);
FastLED.setBrightness(50);
}
void loop() {
for (int colorIndex = 0; colorIndex < sizeof(colors) / sizeof(colors[0]); ++colorIndex) {
for (int segmentIndex = 0; segmentIndex < NUM_SEGMENTS; ++segmentIndex) {
int currentColorIndex = (colorIndex + segmentIndex * 3) % (sizeof(colors) / sizeof(colors[0]));
runningLightEffect(ledArrays[segmentIndex], colors[currentColorIndex], 100);
}
FastLED.delay(100);
}
}
void runningLightEffect(CRGB *leds, CRGB color, int delayTime) {
for (int i = 0; i < SEGMENT_SIZE; ++i) {
leds[i] = color;
FastLED.show();
FastLED.delay(delayTime);
// Turn off the current LED before moving to the next one
leds[i] = CRGB::Black;
}
}