Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- // --- CONFIGURATION ---
- #define LED_PIN 4
- #define NUM_LEDS 122
- #define LED_TYPE WS2812B
- #define COLOR_ORDER GRB
- // --- ZONES ---
- const int G_TRONC = 5;
- const int G_FEUILLES = 15;
- const int G_BRANCHES = 5;
- const int D_BRANCHES = 5;
- const int D_FEUILLES = 10;
- const int D_TRONC = 5;
- const int ZONE_ETOILE_DEBUT = G_TRONC + G_FEUILLES + G_BRANCHES;
- const int ZONE_ETOILE_FIN = NUM_LEDS - (D_BRANCHES + D_FEUILLES + D_TRONC);
- // --- LUMIERE ---
- const int GLOBAL_BRIGHTNESS = 120;
- const int STAR_BRIGHTNESS = 255;
- // --- COULEURS ---
- CRGB rawMoon = CRGB(180, 160, 100);
- CRGB rawForest = CRGB(0, 255, 40);
- CRGB rawWood = CRGB(255, 110, 0);
- // Couleur de nuit standard (pour le bois et le ciel)
- CRGB nightWhite = CRGB(30, 30, 40);
- // --- PARAMETRES ETOILE ---
- const unsigned long STAR_INTERVAL = 10000;
- const int STAR_SPEED = 18;
- const int STAR_LENGTH = 10;
- CRGB leds[NUM_LEDS];
- // --- VARIABLES ---
- unsigned long lastStarTime = 0;
- bool isStarRunning = false;
- int starPosition = 0;
- unsigned long lastMoveTime = 0;
- bool starDirectionReverse = false;
- float currentDimFactor = 1.0;
- float dayNightRatio = 1.0;
- bool isNightMode = false;
- int passCounter = 0;
- const int TARGET_PASSES = 2;
- void setup() {
- delay(1000);
- FastLED.setMaxPowerInVoltsAndMilliamps(5, 1500);
- FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(GLOBAL_BRIGHTNESS);
- fill_solid(leds, NUM_LEDS, CRGB::Black);
- FastLED.show();
- }
- void loop() {
- unsigned long currentMillis = millis();
- // 1. DÉCLENCHEMENT DE L'ÉTOILE
- if (!isStarRunning && (currentMillis - lastStarTime > STAR_INTERVAL)) {
- isStarRunning = true;
- lastStarTime = currentMillis;
- if (starDirectionReverse) {
- starPosition = ZONE_ETOILE_FIN + STAR_LENGTH;
- } else {
- starPosition = ZONE_ETOILE_DEBUT - STAR_LENGTH;
- }
- }
- // 2. GESTION JOUR / NUIT
- if (isNightMode) {
- if (dayNightRatio > 0.0) dayNightRatio -= 0.002;
- if (dayNightRatio < 0.0) dayNightRatio = 0.0;
- } else {
- if (dayNightRatio < 1.0) dayNightRatio += 0.002;
- if (dayNightRatio > 1.0) dayNightRatio = 1.0;
- }
- // 3. FACTEUR D'ASSOMBRISSEMENT
- if (isStarRunning) {
- if (currentDimFactor > 0.5) {
- currentDimFactor -= 0.02;
- }
- } else {
- if (currentDimFactor < 1.0) {
- currentDimFactor += 0.005;
- }
- }
- // 4. CALCUL DES COULEURS
- // MODIF 2 : La forêt la nuit est plus lumineuse
- CRGB nightForestBase = CRGB(150, 190, 150);
- CRGB cWood = blend(nightWhite, rawWood, 255 * dayNightRatio);
- CRGB cForest = blend(nightForestBase, rawForest, 255 * dayNightRatio);
- CRGB cMoon = blend(nightWhite, rawMoon, 255 * dayNightRatio);
- cWood.nscale8(255 * currentDimFactor);
- cForest.nscale8(255 * currentDimFactor);
- cMoon.nscale8(255 * currentDimFactor);
- int cursor = 0;
- fill_solid(leds + cursor, G_TRONC, cWood); cursor += G_TRONC;
- fill_solid(leds + cursor, G_FEUILLES, cForest); cursor += G_FEUILLES;
- fill_solid(leds + cursor, G_BRANCHES, cWood); cursor += G_BRANCHES;
- int moonLen = ZONE_ETOILE_FIN - ZONE_ETOILE_DEBUT;
- fill_solid(leds + cursor, moonLen, cMoon); cursor += moonLen;
- fill_solid(leds + cursor, D_BRANCHES, cWood); cursor += D_BRANCHES;
- fill_solid(leds + cursor, D_FEUILLES, cForest); cursor += D_FEUILLES;
- fill_solid(leds + cursor, D_TRONC, cWood);
- // 5. SCINTILLEMENT (RENFORCÉ)
- if (dayNightRatio < 0.2) {
- for(int k=0; k < 3; k++) {
- if (random8() < 60) {
- int pos = random16(ZONE_ETOILE_DEBUT, ZONE_ETOILE_FIN);
- // MODIF 3 : Valeurs très hautes (200-255) pour un flash blanc/bleu très brillant
- leds[pos] += CRGB(random8(200, 255), random8(200, 255), 255);
- }
- }
- }
- // 6. ANIMATION ETOILE
- if (isStarRunning) {
- if (currentMillis - lastMoveTime >= STAR_SPEED) {
- lastMoveTime = currentMillis;
- bool starFinished = false;
- if (starDirectionReverse) {
- starPosition--;
- if (starPosition < (ZONE_ETOILE_DEBUT - STAR_LENGTH)) starFinished = true;
- } else {
- starPosition++;
- if (starPosition > (ZONE_ETOILE_FIN + STAR_LENGTH)) starFinished = true;
- }
- if (starFinished) {
- isStarRunning = false;
- starDirectionReverse = !starDirectionReverse;
- passCounter++;
- if (passCounter >= TARGET_PASSES) {
- passCounter = 0;
- isNightMode = !isNightMode;
- }
- }
- }
- for (int i = 0; i < STAR_LENGTH; i++) {
- int pixelPos = starDirectionReverse ? (starPosition + i) : (starPosition - i);
- if (pixelPos >= ZONE_ETOILE_DEBUT && pixelPos < ZONE_ETOILE_FIN) {
- CRGB starColor = CRGB::White;
- starColor.nscale8(STAR_BRIGHTNESS);
- uint8_t fadeAmount = 255 - (i * (255 / STAR_LENGTH));
- starColor.nscale8(fadeAmount);
- leds[pixelPos] += starColor;
- }
- }
- }
- FastLED.show();
- FastLED.delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment