Fabouh62

Lamp wolf

Feb 10th, 2026
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.09 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. // --- CONFIGURATION ---
  4. #define LED_PIN 4
  5. #define NUM_LEDS 122
  6. #define LED_TYPE WS2812B
  7. #define COLOR_ORDER GRB
  8.  
  9. // --- ZONES ---
  10. const int G_TRONC = 5;
  11. const int G_FEUILLES = 15;
  12. const int G_BRANCHES = 5;
  13. const int D_BRANCHES = 5;
  14. const int D_FEUILLES = 10;
  15. const int D_TRONC = 5;
  16.  
  17. const int ZONE_ETOILE_DEBUT = G_TRONC + G_FEUILLES + G_BRANCHES;
  18. const int ZONE_ETOILE_FIN = NUM_LEDS - (D_BRANCHES + D_FEUILLES + D_TRONC);
  19.  
  20. // --- LUMIERE ---
  21. const int GLOBAL_BRIGHTNESS = 120;
  22. const int STAR_BRIGHTNESS = 255;
  23.  
  24. // --- COULEURS ---
  25. CRGB rawMoon = CRGB(180, 160, 100);
  26. CRGB rawForest = CRGB(0, 255, 40);
  27. CRGB rawWood = CRGB(255, 110, 0);
  28.  
  29. // Couleur de nuit standard (pour le bois et le ciel)
  30. CRGB nightWhite = CRGB(30, 30, 40);
  31.  
  32. // --- PARAMETRES ETOILE ---
  33. const unsigned long STAR_INTERVAL = 10000;
  34. const int STAR_SPEED = 18;
  35. const int STAR_LENGTH = 10;
  36.  
  37. CRGB leds[NUM_LEDS];
  38.  
  39. // --- VARIABLES ---
  40. unsigned long lastStarTime = 0;
  41. bool isStarRunning = false;
  42. int starPosition = 0;
  43. unsigned long lastMoveTime = 0;
  44. bool starDirectionReverse = false;
  45.  
  46. float currentDimFactor = 1.0;
  47. float dayNightRatio = 1.0;
  48. bool isNightMode = false;
  49. int passCounter = 0;
  50. const int TARGET_PASSES = 2;
  51.  
  52. void setup() {
  53. delay(1000);
  54. FastLED.setMaxPowerInVoltsAndMilliamps(5, 1500);
  55. FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  56. FastLED.setBrightness(GLOBAL_BRIGHTNESS);
  57. fill_solid(leds, NUM_LEDS, CRGB::Black);
  58. FastLED.show();
  59. }
  60.  
  61. void loop() {
  62. unsigned long currentMillis = millis();
  63.  
  64. // 1. DÉCLENCHEMENT DE L'ÉTOILE
  65. if (!isStarRunning && (currentMillis - lastStarTime > STAR_INTERVAL)) {
  66. isStarRunning = true;
  67. lastStarTime = currentMillis;
  68. if (starDirectionReverse) {
  69. starPosition = ZONE_ETOILE_FIN + STAR_LENGTH;
  70. } else {
  71. starPosition = ZONE_ETOILE_DEBUT - STAR_LENGTH;
  72. }
  73. }
  74.  
  75. // 2. GESTION JOUR / NUIT
  76. if (isNightMode) {
  77. if (dayNightRatio > 0.0) dayNightRatio -= 0.002;
  78. if (dayNightRatio < 0.0) dayNightRatio = 0.0;
  79. } else {
  80. if (dayNightRatio < 1.0) dayNightRatio += 0.002;
  81. if (dayNightRatio > 1.0) dayNightRatio = 1.0;
  82. }
  83.  
  84. // 3. FACTEUR D'ASSOMBRISSEMENT
  85. if (isStarRunning) {
  86. if (currentDimFactor > 0.5) {
  87. currentDimFactor -= 0.02;
  88. }
  89. } else {
  90. if (currentDimFactor < 1.0) {
  91. currentDimFactor += 0.005;
  92. }
  93. }
  94.  
  95. // 4. CALCUL DES COULEURS
  96. // MODIF 2 : La forêt la nuit est plus lumineuse
  97. CRGB nightForestBase = CRGB(150, 190, 150);
  98.  
  99. CRGB cWood = blend(nightWhite, rawWood, 255 * dayNightRatio);
  100. CRGB cForest = blend(nightForestBase, rawForest, 255 * dayNightRatio);
  101. CRGB cMoon = blend(nightWhite, rawMoon, 255 * dayNightRatio);
  102.  
  103. cWood.nscale8(255 * currentDimFactor);
  104. cForest.nscale8(255 * currentDimFactor);
  105. cMoon.nscale8(255 * currentDimFactor);
  106.  
  107. int cursor = 0;
  108. fill_solid(leds + cursor, G_TRONC, cWood); cursor += G_TRONC;
  109. fill_solid(leds + cursor, G_FEUILLES, cForest); cursor += G_FEUILLES;
  110. fill_solid(leds + cursor, G_BRANCHES, cWood); cursor += G_BRANCHES;
  111.  
  112. int moonLen = ZONE_ETOILE_FIN - ZONE_ETOILE_DEBUT;
  113. fill_solid(leds + cursor, moonLen, cMoon); cursor += moonLen;
  114.  
  115. fill_solid(leds + cursor, D_BRANCHES, cWood); cursor += D_BRANCHES;
  116. fill_solid(leds + cursor, D_FEUILLES, cForest); cursor += D_FEUILLES;
  117. fill_solid(leds + cursor, D_TRONC, cWood);
  118.  
  119. // 5. SCINTILLEMENT (RENFORCÉ)
  120. if (dayNightRatio < 0.2) {
  121. for(int k=0; k < 3; k++) {
  122. if (random8() < 60) {
  123. int pos = random16(ZONE_ETOILE_DEBUT, ZONE_ETOILE_FIN);
  124.  
  125. // MODIF 3 : Valeurs très hautes (200-255) pour un flash blanc/bleu très brillant
  126. leds[pos] += CRGB(random8(200, 255), random8(200, 255), 255);
  127. }
  128. }
  129. }
  130.  
  131. // 6. ANIMATION ETOILE
  132. if (isStarRunning) {
  133. if (currentMillis - lastMoveTime >= STAR_SPEED) {
  134. lastMoveTime = currentMillis;
  135. bool starFinished = false;
  136.  
  137. if (starDirectionReverse) {
  138. starPosition--;
  139. if (starPosition < (ZONE_ETOILE_DEBUT - STAR_LENGTH)) starFinished = true;
  140. } else {
  141. starPosition++;
  142. if (starPosition > (ZONE_ETOILE_FIN + STAR_LENGTH)) starFinished = true;
  143. }
  144.  
  145. if (starFinished) {
  146. isStarRunning = false;
  147. starDirectionReverse = !starDirectionReverse;
  148. passCounter++;
  149. if (passCounter >= TARGET_PASSES) {
  150. passCounter = 0;
  151. isNightMode = !isNightMode;
  152. }
  153. }
  154. }
  155.  
  156. for (int i = 0; i < STAR_LENGTH; i++) {
  157. int pixelPos = starDirectionReverse ? (starPosition + i) : (starPosition - i);
  158. if (pixelPos >= ZONE_ETOILE_DEBUT && pixelPos < ZONE_ETOILE_FIN) {
  159. CRGB starColor = CRGB::White;
  160. starColor.nscale8(STAR_BRIGHTNESS);
  161. uint8_t fadeAmount = 255 - (i * (255 / STAR_LENGTH));
  162. starColor.nscale8(fadeAmount);
  163. leds[pixelPos] += starColor;
  164. }
  165. }
  166. }
  167.  
  168. FastLED.show();
  169. FastLED.delay(10);
  170. }
  171.  
Tags: stars Wolf
Advertisement
Add Comment
Please, Sign In to add comment