WIP : increase brightnes

This commit is contained in:
Julien Cabillot 2017-04-24 03:12:29 +02:00 committed by Cabillot Julien
parent 2d755898dd
commit 0463f10781
2 changed files with 17 additions and 9 deletions

View File

@ -8,7 +8,10 @@
#include "alarmclock.h" #include "alarmclock.h"
// LED // LED
float brightness = LED_BRIGHTNESS_DEFAULT; // Corresponds à un max brightness configurable via HA
int brightness = LED_BRIGHTNESS_DEFAULT;
// Utilisé pour définir le seuil actuel de brightness
int curbrightness = 0;
int color = LED_COLOR_DEFAULT; int color = LED_COLOR_DEFAULT;
CRGB leds[LED_NUM]; CRGB leds[LED_NUM];
boolean ledState = false; boolean ledState = false;
@ -116,6 +119,7 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length)
ledState = true; ledState = true;
} else { } else {
ledState = false; ledState = false;
curbrightness = 0;
ledBlackAll(); ledBlackAll();
} }
mqttSendState(); mqttSendState();
@ -188,20 +192,24 @@ void ledError()
* Pour éviter un éclairage basique, on applique un breath qui permet * Pour éviter un éclairage basique, on applique un breath qui permet
* de faire respirer la couleur (brightness). * de faire respirer la couleur (brightness).
*/ */
void ledFullColor() void ledDisplay()
{ {
// Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ // Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/
// Voic la version avec la gestion du speed, mais je ne suis pas convaincu
//float breath = (exp(sin(millis() / 2000.0 * map(speed, 0, 255, 50, 300)/100 * PI)) - 0.3678794) * 108.4;
float breath = (exp(sin(millis() / 4000.0 * PI)) - 0.3678794) * 108.4; float breath = (exp(sin(millis() / 4000.0 * PI)) - 0.3678794) * 108.4;
fill_solid(leds, LED_NUM, color); fill_solid(leds, LED_NUM, color);
FastLED.setBrightness(breath); FastLED.setBrightness(map(breath, 0, 255, 0, curbrightness));
FastLED.show(); FastLED.show();
} }
void loop() { void loop() {
// TODO : à voir s'il est plus interressant d'augmenter vite mais graduellement
// TODO : ou de manière moins fréquence mais en faisant un saut de palier.
// TODO : la solution peut aussi etre un mix des deux
EVERY_N_SECONDS(10) {
curbrightness++;
}
// MQTT // MQTT
testConnectMQTT(); testConnectMQTT();
client.loop(); client.loop();
@ -210,6 +218,6 @@ void loop() {
if (!ledState) { if (!ledState) {
FastLED.delay(1000); FastLED.delay(1000);
} else { } else {
ledFullColor(); ledDisplay();
} }
} }

View File

@ -5,7 +5,7 @@
#define LED_PIN 5 // = D1 #define LED_PIN 5 // = D1
#define LED_CHIPSET WS2812B #define LED_CHIPSET WS2812B
#define LED_COLOR_ORDER GRB #define LED_COLOR_ORDER GRB
#define LED_BRIGHTNESS_DEFAULT 96 #define LED_BRIGHTNESS_DEFAULT 0
#define LED_COLOR_DEFAULT CRGB::Red #define LED_COLOR_DEFAULT CRGB::Red
// WIFI // WIFI
@ -39,4 +39,4 @@ void mqttSendBrightnessState();
void mqttSendColorState(); void mqttSendColorState();
void ledBlackAll(); void ledBlackAll();
void ledError(); void ledError();
void ledFullColor(); void ledDisplay();