Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #define PIN_LED 4
- #define NB_LED 68
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(NB_LED, PIN_LED, NEO_GRB + NEO_KHZ800);
- unsigned long debutCycle = 0;
- unsigned long prochainEvent = 0;
- bool flash = false;
- unsigned long finFlash = 0;
- void setup() {
- strip.begin();
- strip.show();
- randomSeed(analogRead(0));
- debutCycle = millis();
- }
- void loop() {
- unsigned long t = millis();
- // Durée exacte du cycle = 7000 ms (3s orage + 4s calme)
- unsigned long elapsed = t - debutCycle;
- // ----- RESTART CYCLE -----
- if (elapsed >= 7000) {
- debutCycle = t;
- elapsed = 0;
- }
- // ============================
- // MODE ORAGE (0-3000 ms)
- // ============================
- if (elapsed < 3000) {
- // FIN D'UN FLASH
- if (flash && t >= finFlash) {
- flash = false;
- setRougeNormal();
- setBlancFixe();
- strip.show();
- prochainEvent = t + random(80, 200);
- }
- // DÉBUT D’UN FLASH
- if (!flash && t >= prochainEvent) {
- flash = true;
- finFlash = t + random(40, 120);
- setRougeFlash();
- setBlancFixe();
- strip.show();
- // Rafales aléatoires
- if (random(0, 10) < 4)
- prochainEvent = t + random(40, 120);
- else
- prochainEvent = finFlash + random(200, 500);
- }
- return;
- }
- // ============================
- // MODE CALME (3000-7000 ms)
- // ============================
- flash = false;
- setRougeNormal();
- setBlancFixe();
- strip.show();
- }
- // =================================
- // FONCTIONS LED
- // =================================
- // Rouge flash fort (orage)
- void setRougeFlash() {
- for (int i = 0; i < 12; i++)
- strip.setPixelColor(i, strip.Color(255, 0, 0));
- for (int i = 44; i < 68; i++)
- strip.setPixelColor(i, strip.Color(255, 0, 0));
- }
- // Rouge normal (calme)
- void setRougeNormal() {
- for (int i = 0; i < 12; i++)
- strip.setPixelColor(i, strip.Color(40, 0, 0));
- for (int i = 44; i < 68; i++)
- strip.setPixelColor(i, strip.Color(40, 0, 0));
- }
- // LEDs blanches fixes
- void setBlancFixe() {
- for (int i = 12; i < 44; i++)
- strip.setPixelColor(i, strip.Color(60, 60, 60));
- }
Advertisement
Add Comment
Please, Sign In to add comment