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.

85 lines
2.0 KiB

3 years ago
  1. #include "Arduino.h"
  2. #include <FastLED.h>
  3. #include "ledmask.h"
  4. /*
  5. TODO: à adapter
  6. LED attached from pin 13 to ground
  7. pushbutton attached to pin 2 from +5V
  8. 10K resistor attached to pin 2 from ground
  9. */
  10. /** FIRE2012 **/
  11. void Fire2012()
  12. {
  13. // Array of temperature readings at each simulation cell
  14. static byte heat[LED_NUM];
  15. // Step 1. Cool down every cell a little
  16. for( int i = 0; i < LED_NUM; i++) {
  17. heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / LED_NUM) + 2));
  18. }
  19. // Step 2. Heat from each cell drifts 'up' and diffuses a little
  20. for( int k= LED_NUM - 1; k >= 2; k--) {
  21. heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
  22. }
  23. // Step 3. Randomly ignite new 'sparks' of heat near the bottom
  24. if( random8() < SPARKING ) {
  25. int y = random8(7);
  26. heat[y] = qadd8( heat[y], random8(160,255) );
  27. }
  28. // Step 4. Map from heat cells to LED colors
  29. for( int j = 0; j < LED_NUM; j++) {
  30. CRGB color = HeatColor( heat[j]);
  31. int pixelnumber;
  32. if( gReverseDirection ) {
  33. pixelnumber = (LED_NUM - 1) - j;
  34. } else {
  35. pixelnumber = j;
  36. }
  37. leds[pixelnumber] = color;
  38. }
  39. }
  40. void setup() {
  41. Serial.begin(SERIAL_SPEED);
  42. Serial.println("\nresetting");
  43. /** BOUTON **/
  44. // powering button
  45. pinMode(POWERPIN, OUTPUT);
  46. digitalWrite(POWERPIN, HIGH);
  47. // initialize the pushbutton pin as an input:
  48. pinMode(BUTTON_PIN, INPUT);
  49. buttonState = 0;
  50. delay(200);
  51. /** LEDS **/
  52. LEDS.addLeds<LED_CHIPSET,LED_PIN, LED_COLOR_ORDER>(leds, LED_NUM).setCorrection(TypicalSMD5050);
  53. FastLED.setBrightness(LED_BRIGHTNESS);
  54. }
  55. void loop() {
  56. /** BOUTON **/
  57. EVERY_N_MILLISECONDS(500) {
  58. buttonState = digitalRead(BUTTON_PIN);
  59. if (buttonState == HIGH) {
  60. Serial.println("HIGH");
  61. } else {
  62. Serial.println("LOW");
  63. }
  64. }
  65. // Add entropy to random number generator; we use a lot of it.
  66. random16_add_entropy(random());
  67. Fire2012(); // run simulation frame
  68. FastLED.show(); // display this frame
  69. FastLED.delay(1000 / LED_FPS);
  70. }