diff --git a/src/ledmask.cpp b/src/ledmask.cpp index 0e430aa..fcf8ccd 100644 --- a/src/ledmask.cpp +++ b/src/ledmask.cpp @@ -1,9 +1,35 @@ #include "Arduino.h" +// TODO : ce serait l'occasion de jouer avec les submodules pour mettre +// fastled dans le dossier lib #include #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 **/ /** * Coupe tout le strip de led. @@ -15,46 +41,32 @@ void ledBlackAll() } /** 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() { -// Array of temperature readings at each simulation cell + // 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)); - } + 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.println("\nresetting"); - /** BOUTON **/ + /** BOUTON EYES **/ // 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: - 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.addLeds(leds, LED_NUM).setCorrection(TypicalSMD5050); @@ -78,27 +96,20 @@ void setup() { void loop() { /** 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 **/ - 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. random16_add_entropy(random()); - Fire2012(); // run simulation frame + Fire2012(); FastLED.delay(1000 / LED_FPS); } else { - // TODO : ne devrait pas être aussi simple, il faut que les yeux se fadent ledBlackAll(); } } diff --git a/src/ledmask.h b/src/ledmask.h index 10aa556..55165a9 100644 --- a/src/ledmask.h +++ b/src/ledmask.h @@ -1,20 +1,21 @@ #define SERIAL_SPEED 9600 /** BOUTON **/ -#define BUTTON_POWER_PIN 2 -#define BUTTON_PIN 3 - -int buttonState; +#define BUTTON_EYES_POWERPIN 2 +#define BUTTON_EYES_PIN 3 +#define BUTTON_PARTY_POWERPIN 4 +#define BUTTON_PARTY_PIN 5 /** LED **/ -#define LED_PIN 5 +#define LED_PIN 6 #define LED_CHIPSET WS2812B #define LED_COLOR_ORDER GRB -#define LED_NUM 30 +#define LED_NUM 6 #define LED_BRIGHTNESS 200 #define LED_FPS 60 -const bool gReverseDirection = false; +bool ledPartyState = false; +bool ledEyesState = false; CRGB leds[LED_NUM]; void ledBlackAll();