Fabouh62

Stranger Things Ring lamp

Dec 15th, 2025
2,555
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2.  
  3. #define PIN_LED 4
  4. #define NB_LED 68
  5.  
  6. Adafruit_NeoPixel strip = Adafruit_NeoPixel(NB_LED, PIN_LED, NEO_GRB + NEO_KHZ800);
  7.  
  8. unsigned long debutCycle = 0;
  9. unsigned long prochainEvent = 0;
  10. bool flash = false;
  11. unsigned long finFlash = 0;
  12.  
  13. void setup() {
  14. strip.begin();
  15. strip.show();
  16. randomSeed(analogRead(0));
  17. debutCycle = millis();
  18. }
  19.  
  20. void loop() {
  21. unsigned long t = millis();
  22.  
  23. // Durée exacte du cycle = 7000 ms (3s orage + 4s calme)
  24. unsigned long elapsed = t - debutCycle;
  25.  
  26. // ----- RESTART CYCLE -----
  27. if (elapsed >= 7000) {
  28. debutCycle = t;
  29. elapsed = 0;
  30. }
  31.  
  32. // ============================
  33. // MODE ORAGE (0-3000 ms)
  34. // ============================
  35. if (elapsed < 3000) {
  36.  
  37. // FIN D'UN FLASH
  38. if (flash && t >= finFlash) {
  39. flash = false;
  40. setRougeNormal();
  41. setBlancFixe();
  42. strip.show();
  43. prochainEvent = t + random(80, 200);
  44. }
  45.  
  46. // DÉBUT D’UN FLASH
  47. if (!flash && t >= prochainEvent) {
  48. flash = true;
  49. finFlash = t + random(40, 120);
  50.  
  51. setRougeFlash();
  52. setBlancFixe();
  53. strip.show();
  54.  
  55. // Rafales aléatoires
  56. if (random(0, 10) < 4)
  57. prochainEvent = t + random(40, 120);
  58. else
  59. prochainEvent = finFlash + random(200, 500);
  60. }
  61.  
  62. return;
  63. }
  64.  
  65. // ============================
  66. // MODE CALME (3000-7000 ms)
  67. // ============================
  68. flash = false;
  69. setRougeNormal();
  70. setBlancFixe();
  71. strip.show();
  72. }
  73.  
  74.  
  75.  
  76. // =================================
  77. // FONCTIONS LED
  78. // =================================
  79.  
  80. // Rouge flash fort (orage)
  81. void setRougeFlash() {
  82. for (int i = 0; i < 12; i++)
  83. strip.setPixelColor(i, strip.Color(255, 0, 0));
  84. for (int i = 44; i < 68; i++)
  85. strip.setPixelColor(i, strip.Color(255, 0, 0));
  86. }
  87.  
  88. // Rouge normal (calme)
  89. void setRougeNormal() {
  90. for (int i = 0; i < 12; i++)
  91. strip.setPixelColor(i, strip.Color(40, 0, 0));
  92. for (int i = 44; i < 68; i++)
  93. strip.setPixelColor(i, strip.Color(40, 0, 0));
  94. }
  95.  
  96. // LEDs blanches fixes
  97. void setBlancFixe() {
  98. for (int i = 12; i < 44; i++)
  99. strip.setPixelColor(i, strip.Color(60, 60, 60));
  100. }
  101.  
Advertisement
Add Comment
Please, Sign In to add comment