|
|
@ -1,9 +1,35 @@ |
|
|
#include "Arduino.h"
|
|
|
#include "Arduino.h"
|
|
|
|
|
|
|
|
|
|
|
|
// TODO : ce serait l'occasion de jouer avec les submodules pour mettre
|
|
|
|
|
|
// fastled dans le dossier lib
|
|
|
#include <FastLED.h>
|
|
|
#include <FastLED.h>
|
|
|
|
|
|
|
|
|
#include "ledmask.h"
|
|
|
#include "ledmask.h"
|
|
|
|
|
|
|
|
|
|
|
|
/** BUTTON **/ |
|
|
|
|
|
void buttonCheckState() { |
|
|
|
|
|
if (digitalRead(BUTTON_EYES_PIN) == HIGH) { |
|
|
|
|
|
Serial.println("E: HIGH"); |
|
|
|
|
|
ledPartyState = false; |
|
|
|
|
|
if (ledEyesState) { |
|
|
|
|
|
ledEyesState = true; |
|
|
|
|
|
} else { |
|
|
|
|
|
ledEyesState = false; |
|
|
|
|
|
// TODO : lancer le "déclin" des yeux
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (digitalRead(BUTTON_PARTY_PIN) == HIGH) { |
|
|
|
|
|
Serial.println("P: HIGH"); |
|
|
|
|
|
ledEyesState = false; |
|
|
|
|
|
if (ledPartyState) { |
|
|
|
|
|
ledPartyState = true; |
|
|
|
|
|
} else { |
|
|
|
|
|
ledPartyState = false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** LEDS **/ |
|
|
/** LEDS **/ |
|
|
/**
|
|
|
/**
|
|
|
* Coupe tout le strip de led. |
|
|
* Coupe tout le strip de led. |
|
|
@ -15,46 +41,32 @@ void ledBlackAll() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** FIRE2012 **/ |
|
|
/** FIRE2012 **/ |
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
TODO: à adapter |
|
|
|
|
|
LED attached from pin 13 to ground |
|
|
|
|
|
pushbutton attached to pin 2 from +5V |
|
|
|
|
|
10K resistor attached to pin 2 from ground |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
void Fire2012() |
|
|
void Fire2012() |
|
|
{ |
|
|
{ |
|
|
// Array of temperature readings at each simulation cell
|
|
|
|
|
|
|
|
|
// Array of temperature readings at each simulation cell
|
|
|
static byte heat[LED_NUM]; |
|
|
static byte heat[LED_NUM]; |
|
|
|
|
|
|
|
|
// Step 1. Cool down every cell a little
|
|
|
// 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)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
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 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 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; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// Step 4. Map from heat cells to LED colors
|
|
|
|
|
|
for (int j = 0; j < LED_NUM; j++) { |
|
|
|
|
|
CRGB color = HeatColor(heat[j]); |
|
|
|
|
|
leds[(LED_NUM - 1) - j] = color; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -62,14 +74,20 @@ void setup() { |
|
|
Serial.begin(SERIAL_SPEED); |
|
|
Serial.begin(SERIAL_SPEED); |
|
|
Serial.println("\nresetting"); |
|
|
Serial.println("\nresetting"); |
|
|
|
|
|
|
|
|
/** BOUTON **/ |
|
|
|
|
|
|
|
|
/** BOUTON EYES **/ |
|
|
// powering button
|
|
|
// powering button
|
|
|
pinMode(BUTTON_POWER_PIN, OUTPUT); |
|
|
|
|
|
digitalWrite(BUTTON_POWER_PIN, HIGH); |
|
|
|
|
|
|
|
|
pinMode(BUTTON_EYES_POWERPIN, OUTPUT); |
|
|
|
|
|
digitalWrite(BUTTON_EYES_POWERPIN, HIGH); |
|
|
// initialize the pushbutton pin as an input:
|
|
|
// initialize the pushbutton pin as an input:
|
|
|
pinMode(BUTTON_PIN, INPUT); |
|
|
|
|
|
buttonState = 0; |
|
|
|
|
|
delay(200); |
|
|
|
|
|
|
|
|
pinMode(BUTTON_EYES_PIN, INPUT); |
|
|
|
|
|
|
|
|
|
|
|
/** BOUTON PARTY **/ |
|
|
|
|
|
// powering button
|
|
|
|
|
|
pinMode(BUTTON_PARTY_POWERPIN, OUTPUT); |
|
|
|
|
|
digitalWrite(BUTTON_PARTY_POWERPIN, HIGH); |
|
|
|
|
|
// initialize the pushbutton pin as an input:
|
|
|
|
|
|
pinMode(BUTTON_PARTY_PIN, INPUT); |
|
|
|
|
|
delay(100); |
|
|
|
|
|
|
|
|
/** LEDS **/ |
|
|
/** LEDS **/ |
|
|
LEDS.addLeds<LED_CHIPSET,LED_PIN, LED_COLOR_ORDER>(leds, LED_NUM).setCorrection(TypicalSMD5050); |
|
|
LEDS.addLeds<LED_CHIPSET,LED_PIN, LED_COLOR_ORDER>(leds, LED_NUM).setCorrection(TypicalSMD5050); |
|
|
@ -78,27 +96,20 @@ void setup() { |
|
|
|
|
|
|
|
|
void loop() { |
|
|
void loop() { |
|
|
/** BOUTON **/ |
|
|
/** BOUTON **/ |
|
|
// TODO : temporaire car le but est d'appuyer sur le boutton pour lancer/couper les yeux
|
|
|
|
|
|
// pas de rester appuyé dessus
|
|
|
|
|
|
EVERY_N_MILLISECONDS(500) { |
|
|
|
|
|
buttonState = digitalRead(BUTTON_PIN); |
|
|
|
|
|
|
|
|
|
|
|
if (buttonState == HIGH) { |
|
|
|
|
|
Serial.println("HIGH"); |
|
|
|
|
|
} else { |
|
|
|
|
|
Serial.println("LOW"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
EVERY_N_MILLISECONDS(300) { |
|
|
|
|
|
buttonCheckState(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** LEDS **/ |
|
|
/** LEDS **/ |
|
|
if (buttonState == HIGH) { |
|
|
|
|
|
// TODO : il faudra ici conditioner l'animation au fait que le button n'ai pas été pressé
|
|
|
|
|
|
|
|
|
if (ledEyesState) { |
|
|
|
|
|
fill_solid(leds, LED_NUM, CRGB::Red); |
|
|
|
|
|
FastLED.delay(1000 / LED_FPS); |
|
|
|
|
|
} else if (ledPartyState) { |
|
|
// Add entropy to random number generator; we use a lot of it.
|
|
|
// Add entropy to random number generator; we use a lot of it.
|
|
|
random16_add_entropy(random()); |
|
|
random16_add_entropy(random()); |
|
|
Fire2012(); // run simulation frame
|
|
|
|
|
|
|
|
|
Fire2012(); |
|
|
FastLED.delay(1000 / LED_FPS); |
|
|
FastLED.delay(1000 / LED_FPS); |
|
|
} else { |
|
|
} else { |
|
|
// TODO : ne devrait pas être aussi simple, il faut que les yeux se fadent
|
|
|
|
|
|
ledBlackAll(); |
|
|
ledBlackAll(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |