[WIP] les boutons controlents les effets + beautification + simplification
This commit is contained in:
parent
0326215637
commit
ee2d9a5d69
@ -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,14 +41,6 @@ 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
|
||||||
@ -47,13 +65,7 @@ void Fire2012()
|
|||||||
// Step 4. Map from heat cells to LED colors
|
// Step 4. Map from heat cells to LED colors
|
||||||
for (int j = 0; j < LED_NUM; j++) {
|
for (int j = 0; j < LED_NUM; j++) {
|
||||||
CRGB color = HeatColor(heat[j]);
|
CRGB color = HeatColor(heat[j]);
|
||||||
int pixelnumber;
|
leds[(LED_NUM - 1) - j] = color;
|
||||||
if( gReverseDirection ) {
|
|
||||||
pixelnumber = (LED_NUM - 1) - j;
|
|
||||||
} else {
|
|
||||||
pixelnumber = j;
|
|
||||||
}
|
|
||||||
leds[pixelnumber] = 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);
|
pinMode(BUTTON_EYES_POWERPIN, OUTPUT);
|
||||||
digitalWrite(BUTTON_POWER_PIN, HIGH);
|
digitalWrite(BUTTON_EYES_POWERPIN, HIGH);
|
||||||
// initialize the pushbutton pin as an input:
|
// initialize the pushbutton pin as an input:
|
||||||
pinMode(BUTTON_PIN, INPUT);
|
pinMode(BUTTON_EYES_PIN, INPUT);
|
||||||
buttonState = 0;
|
|
||||||
delay(200);
|
/** 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
|
EVERY_N_MILLISECONDS(300) {
|
||||||
// pas de rester appuyé dessus
|
buttonCheckState();
|
||||||
EVERY_N_MILLISECONDS(500) {
|
|
||||||
buttonState = digitalRead(BUTTON_PIN);
|
|
||||||
|
|
||||||
if (buttonState == HIGH) {
|
|
||||||
Serial.println("HIGH");
|
|
||||||
} else {
|
|
||||||
Serial.println("LOW");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** LEDS **/
|
/** LEDS **/
|
||||||
if (buttonState == HIGH) {
|
if (ledEyesState) {
|
||||||
// TODO : il faudra ici conditioner l'animation au fait que le button n'ai pas été pressé
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,20 +1,21 @@
|
|||||||
#define SERIAL_SPEED 9600
|
#define SERIAL_SPEED 9600
|
||||||
|
|
||||||
/** BOUTON **/
|
/** BOUTON **/
|
||||||
#define BUTTON_POWER_PIN 2
|
#define BUTTON_EYES_POWERPIN 2
|
||||||
#define BUTTON_PIN 3
|
#define BUTTON_EYES_PIN 3
|
||||||
|
#define BUTTON_PARTY_POWERPIN 4
|
||||||
int buttonState;
|
#define BUTTON_PARTY_PIN 5
|
||||||
|
|
||||||
/** LED **/
|
/** LED **/
|
||||||
#define LED_PIN 5
|
#define LED_PIN 6
|
||||||
#define LED_CHIPSET WS2812B
|
#define LED_CHIPSET WS2812B
|
||||||
#define LED_COLOR_ORDER GRB
|
#define LED_COLOR_ORDER GRB
|
||||||
#define LED_NUM 30
|
#define LED_NUM 6
|
||||||
#define LED_BRIGHTNESS 200
|
#define LED_BRIGHTNESS 200
|
||||||
#define LED_FPS 60
|
#define LED_FPS 60
|
||||||
|
|
||||||
const bool gReverseDirection = false;
|
bool ledPartyState = false;
|
||||||
|
bool ledEyesState = false;
|
||||||
CRGB leds[LED_NUM];
|
CRGB leds[LED_NUM];
|
||||||
|
|
||||||
void ledBlackAll();
|
void ledBlackAll();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user