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.
 
 

87 lines
2.2 KiB

#include "Arduino.h"
#include <FastLED.h>
#include "ledmask.h"
/*
TODO: à adapter
LED attached from pin 13 to ground
pushbutton attached to pin 2 from +5V
10K resistor attached to pin 2 from ground
*/
/** FIRE2012 **/
void Fire2012()
{
// Array of temperature readings at each simulation cell
static byte heat[LED_NUM];
// Step 1. Cool down every cell a little
for( int i = 0; i < LED_NUM; i++) {
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / LED_NUM) + 2));
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( int k= LED_NUM - 1; k >= 2; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
}
// Step 3. Randomly ignite new 'sparks' of heat near the bottom
if( random8() < SPARKING ) {
int y = random8(7);
heat[y] = qadd8( heat[y], random8(160,255) );
}
// Step 4. Map from heat cells to LED colors
for( int j = 0; j < LED_NUM; j++) {
CRGB color = HeatColor( heat[j]);
int pixelnumber;
if( gReverseDirection ) {
pixelnumber = (LED_NUM - 1) - j;
} else {
pixelnumber = j;
}
leds[pixelnumber] = color;
}
}
void setup() {
Serial.begin(SERIAL_SPEED);
Serial.println("\nresetting");
/** BOUTON **/
// powering button
pinMode(BUTTON_POWER_PIN, OUTPUT);
digitalWrite(BUTTON_POWER_PIN, HIGH);
// initialize the pushbutton pin as an input:
pinMode(BUTTON_PIN, INPUT);
buttonState = 0;
delay(200);
/** LEDS **/
LEDS.addLeds<LED_CHIPSET,LED_PIN, LED_COLOR_ORDER>(leds, LED_NUM).setCorrection(TypicalSMD5050);
FastLED.setBrightness(LED_BRIGHTNESS);
}
void loop() {
/** BOUTON **/
EVERY_N_MILLISECONDS(500) {
buttonState = digitalRead(BUTTON_PIN);
if (buttonState == HIGH) {
Serial.println("HIGH");
} else {
Serial.println("LOW");
}
}
/** LEDS **/
// TODO : il faudra ici conditioner l'animation au fait que le button n'ai pas été pressé
// Add entropy to random number generator; we use a lot of it.
random16_add_entropy(random());
Fire2012(); // run simulation frame
FastLED.show(); // display this frame
FastLED.delay(1000 / LED_FPS);
}