Masque Halloween illuminé
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.7 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. #include "Arduino.h"
  2. // TODO : ce serait l'occasion de jouer avec les submodules pour mettre
  3. // fastled dans le dossier lib
  4. #include <FastLED.h>
  5. #include "ledmask.h"
  6. /** BUTTON **/
  7. void buttonCheckState() {
  8. if (digitalRead(BUTTON_EYES_PIN) == HIGH) {
  9. Serial.println("E: HIGH");
  10. ledPartyState = false;
  11. if (ledEyesState) {
  12. ledEyesState = true;
  13. // TODO : lancer l' "ouverture" des yeux
  14. } else {
  15. ledEyesState = false;
  16. // TODO : lancer le "déclin" des yeux
  17. }
  18. }
  19. if (digitalRead(BUTTON_PARTY_PIN) == HIGH) {
  20. Serial.println("P: HIGH");
  21. ledEyesState = false;
  22. if (ledPartyState) {
  23. ledPartyState = true;
  24. } else {
  25. ledPartyState = false;
  26. }
  27. }
  28. }
  29. /** LEDS **/
  30. /**
  31. * Coupe tout le strip de led.
  32. */
  33. void ledBlackAll()
  34. {
  35. FastLED.clear();
  36. FastLED.show();
  37. }
  38. /** FIRE2012 **/
  39. void Fire2012()
  40. {
  41. // Array of temperature readings at each simulation cell
  42. static byte heat[LED_NUM];
  43. // Step 1. Cool down every cell a little
  44. for (int i = 0; i < LED_NUM; i++) {
  45. heat[i] = qsub8(heat[i], random8(0, ((COOLING * 10) / LED_NUM) + 2));
  46. }
  47. // Step 2. Heat from each cell drifts 'up' and diffuses a little
  48. for (int k = LED_NUM - 1; k >= 2; k--) {
  49. heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
  50. }
  51. // Step 3. Randomly ignite new 'sparks' of heat near the bottom
  52. if (random8() < SPARKING ) {
  53. int y = random8(7);
  54. heat[y] = qadd8(heat[y], random8(160,255));
  55. }
  56. // Step 4. Map from heat cells to LED colors
  57. for (int j = 0; j < LED_NUM; j++) {
  58. CRGB color = HeatColor(heat[j]);
  59. leds[(LED_NUM - 1) - j] = color;
  60. }
  61. }
  62. void setup() {
  63. Serial.begin(SERIAL_SPEED);
  64. Serial.println("\nresetting");
  65. /** BOUTON EYES **/
  66. // powering button
  67. pinMode(BUTTON_EYES_POWERPIN, OUTPUT);
  68. digitalWrite(BUTTON_EYES_POWERPIN, HIGH);
  69. // initialize the pushbutton pin as an input:
  70. pinMode(BUTTON_EYES_PIN, INPUT);
  71. /** BOUTON PARTY **/
  72. // powering button
  73. pinMode(BUTTON_PARTY_POWERPIN, OUTPUT);
  74. digitalWrite(BUTTON_PARTY_POWERPIN, HIGH);
  75. // initialize the pushbutton pin as an input:
  76. pinMode(BUTTON_PARTY_PIN, INPUT);
  77. delay(100);
  78. /** LEDS **/
  79. LEDS.addLeds<LED_CHIPSET,LED_PIN, LED_COLOR_ORDER>(leds, LED_NUM).setCorrection(TypicalSMD5050);
  80. FastLED.setBrightness(LED_BRIGHTNESS);
  81. }
  82. void loop() {
  83. /** BOUTON **/
  84. EVERY_N_MILLISECONDS(300) {
  85. buttonCheckState();
  86. }
  87. /** LEDS **/
  88. if (ledEyesState) {
  89. fill_solid(leds, LED_NUM, CRGB::Red);
  90. FastLED.delay(1000 / LED_FPS);
  91. } else if (ledPartyState) {
  92. // Add entropy to random number generator; we use a lot of it.
  93. random16_add_entropy(random());
  94. Fire2012();
  95. FastLED.delay(1000 / LED_FPS);
  96. } else {
  97. ledBlackAll();
  98. }
  99. }