#include <FastLED.h>
#define NUM_LEDS 9
#define DATA_PIN 4
CRGB ledsArray[NUM_LEDS];
struct LedState {
bool isOn = false;
CRGB color = CRGB::Black;
unsigned long onTime = 0;
unsigned long duration = 0;
};
LedState leds[NUM_LEDS];
unsigned long lastActivation = 0;
unsigned long nextActivationDelay = 0;
unsigned int totalOn=0;
void setup() {
FastLED.addLeds<WS2812, DATA_PIN, GRB>(ledsArray, NUM_LEDS);
FastLED.clear();
FastLED.show();
nextActivationDelay = random(500, 1000); // перша активація
Serial.begin(115200);
}
void loop() {
unsigned long now = millis();
// Вимикаємо ті, що "перегоріли"
for (int i = 0; i < NUM_LEDS; i++) {
if (leds[i].isOn && (now - leds[i].onTime > leds[i].duration)) {
leds[i].isOn = false;
ledsArray[i] = CRGB::Black;
totalOn--;
}
}
// Періодично активуємо нові
if (now - lastActivation >= nextActivationDelay) {
Serial.print("Total LEDs On: ");
Serial.println(totalOn);
if(totalOn<4) {
int newCount = random(1, 5-totalOn); // від 1 до 4 нових LED
for (int j = 0; j < newCount; j++) {
int idx = random(0, NUM_LEDS);
leds[idx].isOn = true;
leds[idx].onTime = now;
leds[idx].duration = random(5000, 15000); // світиться 1-5 сек
leds[idx].color = CRGB(random(255), random(255), random(255));
ledsArray[idx] = leds[idx].color;
totalOn++;
}
lastActivation = now;
nextActivationDelay = random(1500, 5000); // наступна активація
}
}
FastLED.show();
delay(10);
}