From a8c09dd27b00f2f5875c0ac74608f52284c189f7 Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Fri, 10 Mar 2017 11:01:33 +0100 Subject: [PATCH 01/15] ajout de colorpattern --- arduino/mqttfastledmenu/mqttfastledmenu.cpp | 119 +++++++++++++++++++- 1 file changed, 117 insertions(+), 2 deletions(-) diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index a8d2fdb..0f5d381 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -1,11 +1,14 @@ #include -#include "mqttfastledmenu.h" - +// TODO : essayer, devrait limiter le flikering +//#define FASTLED_ALLOW_INTERRUPTS 0 +#define FASTLED_ESP8266_NODEMCU_PIN_ORDER #include #include #include +#include "mqttfastledmenu.h" + // LED int brightness = LED_BRIGHTNESS_DEFAULT; int color = LED_COLOR_DEFAULT; @@ -21,6 +24,15 @@ WiFiClient espClient; char message_buff[100]; PubSubClient client(espClient); + +//////////////////////////////// ColorPalette +CRGBPalette16 currentPalette; +TBlendType currentBlending; + +extern CRGBPalette16 myRedWhiteBluePalette; +extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM; +/////////////////////////////////////////////// + void setup() { Serial.begin(SERIAL_SPEED); @@ -52,6 +64,11 @@ void setup() client.loop(); } + //////////////////////////////////////////////// ColorPalette + currentPalette = RainbowColors_p; + currentBlending = LINEARBLEND; + ///////////////////////////////////////////////////////////// + Serial.println("End of setup"); } @@ -199,6 +216,102 @@ void ledFullColor() FastLED.delay(100 / speed); } +///////////////////////////////// ColorPalette + + +void ledColorPattern() +{ + ChangePalettePeriodically(); + + static uint8_t startIndex = 0; + startIndex = startIndex + 1; /* motion speed */ + + FillLEDsFromPaletteColors( startIndex); + + FastLED.show(); + FastLED.delay(1000 / speed); +} + +void FillLEDsFromPaletteColors( uint8_t colorIndex) +{ + uint8_t brightness = 255; + + for( int i = 0; i < LED_NUM; i++) { + leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending); + colorIndex += 3; + } +} + + +// There are several different palettes of colors demonstrated here. +// +// FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p, +// OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p. +// +// Additionally, you can manually define your own color palettes, or you can write +// code that creates color palettes on the fly. All are shown here. + +void ChangePalettePeriodically() +{ + uint8_t secondHand = (millis() / 1000) % 60; + static uint8_t lastSecond = 99; + + if( lastSecond != secondHand) { + lastSecond = secondHand; + if( secondHand == 0) { currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; } + if( secondHand == 10) { currentPalette = RainbowStripeColors_p; currentBlending = NOBLEND; } + if( secondHand == 15) { currentPalette = RainbowStripeColors_p; currentBlending = LINEARBLEND; } + if( secondHand == 20) { SetupPurpleAndGreenPalette(); currentBlending = LINEARBLEND; } + if( secondHand == 25) { SetupTotallyRandomPalette(); currentBlending = LINEARBLEND; } + if( secondHand == 30) { SetupBlackAndWhiteStripedPalette(); currentBlending = NOBLEND; } + if( secondHand == 35) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; } + if( secondHand == 40) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; } + if( secondHand == 45) { currentPalette = PartyColors_p; currentBlending = LINEARBLEND; } + if( secondHand == 50) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; } + if( secondHand == 55) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; } + } +} + +// This function fills the palette with totally random colors. +void SetupTotallyRandomPalette() +{ + for( int i = 0; i < 16; i++) { + currentPalette[i] = CHSV( random8(), 255, random8()); + } +} + +// This function sets up a palette of black and white stripes, +// using code. Since the palette is effectively an array of +// sixteen CRGB colors, the various fill_* functions can be used +// to set them up. +void SetupBlackAndWhiteStripedPalette() +{ + // 'black out' all 16 palette entries... + fill_solid( currentPalette, 16, CRGB::Black); + // and set every fourth one to white. + currentPalette[0] = CRGB::White; + currentPalette[4] = CRGB::White; + currentPalette[8] = CRGB::White; + currentPalette[12] = CRGB::White; + +} + +// This function sets up a palette of purple and green stripes. +void SetupPurpleAndGreenPalette() +{ + CRGB purple = CHSV( HUE_PURPLE, 255, 255); + CRGB green = CHSV( HUE_GREEN, 255, 255); + CRGB black = CRGB::Black; + + currentPalette = CRGBPalette16( + green, green, black, black, + purple, purple, black, black, + green, green, black, black, + purple, purple, black, black ); +} + +////////////////////////////////////////////////////////////////////////////// + void loop() { // MQTT testConnectMQTT(); @@ -212,6 +325,8 @@ void loop() { ledCylon(); } else if (ledEffect == LED_EFFECT_FULLRED) { ledFullColor(); + } else if (ledEffect == LED_EFFET_COLORPATTERN) { + ledColorPattern(); } else { ledError(); } From 4e0c1ff95042f4e2f67bac2bff00ded468350f71 Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Fri, 10 Mar 2017 11:09:19 +0100 Subject: [PATCH 02/15] ajout de colortemp --- arduino/mqttfastledmenu/mqttfastledmenu.cpp | 34 ++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index 0f5d381..73dbcd9 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -312,6 +312,36 @@ void SetupPurpleAndGreenPalette() ////////////////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////// ColorTemperature +void colorTemp() +{ + // draw a generic, no-name rainbow + static uint8_t starthue = 0; + fill_rainbow( leds + 5, LED_NUM - 5, --starthue, 20); + + // Choose which 'color temperature' profile to enable. + uint8_t secs = (millis() / 1000) % (DISPLAYTIME * 2); + if( secs < DISPLAYTIME) { + FastLED.setTemperature( TEMPERATURE_1 ); // first temperature + leds[0] = TEMPERATURE_1; // show indicator pixel + } else { + FastLED.setTemperature( TEMPERATURE_2 ); // second temperature + leds[0] = TEMPERATURE_2; // show indicator pixel + } + + // Black out the LEDs for a few secnds between color changes + // to let the eyes and brains adjust + if( (secs % DISPLAYTIME) < BLACKTIME) { + memset8( leds, 0, LED_NUM * sizeof(CRGB)); + } + + FastLED.show(); + FastLED.delay(8); +} + +//////////////////////////////////////////////////////////////////// void loop() { // MQTT testConnectMQTT(); @@ -325,8 +355,10 @@ void loop() { ledCylon(); } else if (ledEffect == LED_EFFECT_FULLRED) { ledFullColor(); - } else if (ledEffect == LED_EFFET_COLORPATTERN) { + } else if (ledEffect == LED_EFFECT_COLORPATTERN) { ledColorPattern(); + } else if (ledEffect == LED_EFFECT_COLORTEMP) { + colorTemp(); } else { ledError(); } From 606a4427779f825852a7f0c8a929022dfac73af1 Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Fri, 10 Mar 2017 11:22:03 +0100 Subject: [PATCH 03/15] ajout de fire --- arduino/mqttfastledmenu/mqttfastledmenu.cpp | 43 ++++++++++++++++++++- home-assistant/ha_configuration.yml | 3 ++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index 73dbcd9..c04c9af 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -340,8 +340,47 @@ void colorTemp() FastLED.show(); FastLED.delay(8); } - //////////////////////////////////////////////////////////////////// + + +///////////////////////////////////////////////Fire202 +void fire() +{ +// 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; + } + + FastLED.delay(1000 / speed); +} +///////////////////////////////////////////// + void loop() { // MQTT testConnectMQTT(); @@ -359,6 +398,8 @@ void loop() { ledColorPattern(); } else if (ledEffect == LED_EFFECT_COLORTEMP) { colorTemp(); + } else if (ledEffect == LED_EFFECT_FIRE) { + fire(); } else { ledError(); } diff --git a/home-assistant/ha_configuration.yml b/home-assistant/ha_configuration.yml index 2481434..4fdb266 100644 --- a/home-assistant/ha_configuration.yml +++ b/home-assistant/ha_configuration.yml @@ -11,6 +11,9 @@ input_select: options: - "cylon" - "full" + - "colorp" + - "colort" + - "fire" - "error" input_slider: From 04af91f5d35ac6921684c7b0f080c2b977de9252 Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Fri, 10 Mar 2017 13:29:16 +0100 Subject: [PATCH 04/15] WIP : test cylon progressif --- arduino/mqttfastledmenu/mqttfastledmenu.cpp | 54 ++++++++++++++++++--- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index c04c9af..cc5cfd7 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -166,33 +166,73 @@ void ledBlackAll() FastLED.show(); } +// TODO : faudra sortir toutes ces fonctions dans un autre fichier + void ledCylon() { // Effet cylon : on allume une led, on attends, on eteinds, on passe à la suivante for(int i = 0; i < LED_NUM; i++) { client.loop(); + if (ledEffect != LED_EFFECT_CYLON) { return; } + if ((i - 3) >= 0) { + leds[i - 3] = CRGB::Black; + } + if ((i - 2) >= 0) { + /* + * Se lit 204/256 d'intensité lumineuse + * àhttps://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors + */ + leds[i - 2] %= 204; + } + if ((i - 2) >= 1) { + leds[i - 2] %= 153; + } + leds[i] = color; - FastLED.delay(1000 / speed); - leds[i] = CRGB::Black; + + if ((i + 1) <= LED_NUM) { + leds[i - 2] %= 153; + } + if ((i + 2) <= LED_NUM) { + leds[i - 2] %= 204; + } + FastLED.delay(1000 / speed); } + // led[0] et led[255] sont gérées par la loop précédante for(int i = LED_NUM - 1; i > 0; i--) { client.loop(); - if (ledEffect != LED_EFFECT_CYLON) { - return; + + if ((i - 2) >= 0) { + /* + * Se lit 204/256 d'intensité lumineuse + * àhttps://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors + */ + leds[i - 2] %= 204; + } + if ((i - 2) >= 1) { + leds[i - 2] %= 153; } leds[i] = color; + + if ((i + 1) <= LED_NUM) { + leds[i - 2] %= 153; + } + if ((i + 2) <= LED_NUM) { + leds[i - 2] %= 204; + } + if ((i + 3) <= LED_NUM) { + leds[i - 3] = CRGB::Black; + } + FastLED.delay(1000 / speed); - leds[i] = CRGB::Black; - FastLED.show(); } - FastLED.delay(1000 / speed); } void ledError() From 0391a8051cb8c374d3c9d85903363703e086d9a4 Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Fri, 10 Mar 2017 13:32:51 +0100 Subject: [PATCH 05/15] =?UTF-8?q?id=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- home-assistant/ha_configuration.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/home-assistant/ha_configuration.yml b/home-assistant/ha_configuration.yml index 4fdb266..445e3bc 100644 --- a/home-assistant/ha_configuration.yml +++ b/home-assistant/ha_configuration.yml @@ -5,6 +5,7 @@ mqtt: username: "XXX" password: "XXX" +# TODO : idéee ! préfixé les functions d'un nombre qu'on sort lors du publish, cela permet de n'avoir que des id input_select: strip1_effect: name: "Choix de l'effet" From 22c21a72abd7cb9683240bfb324060bb2531206b Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Fri, 10 Mar 2017 13:46:00 +0100 Subject: [PATCH 06/15] platform veut vraiment ce fichier --- .gitignore | 4 ---- arduino/.gitignore | 4 ++++ arduino/mqttfastledmenu/mqttfastledmenu.cpp | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 arduino/.gitignore diff --git a/.gitignore b/.gitignore index f099378..3647168 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,2 @@ .vscode/* arduino/mqttfastledmenu/mqttfastledmenu.h -arduino/.pioenvs -arduino/.piolibdeps -arduino/.clang_complete -arduino/.gcc-flags.json diff --git a/arduino/.gitignore b/arduino/.gitignore new file mode 100644 index 0000000..5dac9f5 --- /dev/null +++ b/arduino/.gitignore @@ -0,0 +1,4 @@ +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index cc5cfd7..f061c1f 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -8,6 +8,7 @@ #include #include "mqttfastledmenu.h" +#include "ledeffect.c" // LED int brightness = LED_BRIGHTNESS_DEFAULT; From 57865e58681e0d73540bf9c21022bc5011d18334 Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Fri, 10 Mar 2017 13:59:30 +0100 Subject: [PATCH 07/15] oubli de definition dans le .h d'exemple --- arduino/mqttfastledmenu/mqttfastledmenu.cpp | 10 +- .../mqttfastledmenu/mqttfastledmenu.example.h | 134 +++++++++++++++++- 2 files changed, 130 insertions(+), 14 deletions(-) diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index f061c1f..4b7124f 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -8,7 +8,6 @@ #include #include "mqttfastledmenu.h" -#include "ledeffect.c" // LED int brightness = LED_BRIGHTNESS_DEFAULT; @@ -25,13 +24,6 @@ WiFiClient espClient; char message_buff[100]; PubSubClient client(espClient); - -//////////////////////////////// ColorPalette -CRGBPalette16 currentPalette; -TBlendType currentBlending; - -extern CRGBPalette16 myRedWhiteBluePalette; -extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM; /////////////////////////////////////////////// void setup() @@ -273,7 +265,7 @@ void ledColorPattern() FastLED.delay(1000 / speed); } -void FillLEDsFromPaletteColors( uint8_t colorIndex) +void FillLEDsFromPaletteColors(uint8_t colorIndex) { uint8_t brightness = 255; diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.example.h b/arduino/mqttfastledmenu/mqttfastledmenu.example.h index 3653ce5..2ee2ea4 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.example.h +++ b/arduino/mqttfastledmenu/mqttfastledmenu.example.h @@ -10,6 +10,9 @@ #define LED_COLOR_DEFAULT CRGB::Red #define LED_EFFECT_CYLON "cylon" +#define LED_EFFECT_COLORPATTERN "colorp" +#define LED_EFFECT_COLORTEMP "colort" +#define LED_EFFECT_FIRE "fire" #define LED_EFFECT_FULLRED "full" #define LED_EFFECT_ERROR "error" @@ -34,11 +37,6 @@ #define MQTT_LED_COLOR_COMMAND "strip1/color/switch" #define MQTT_LED_COLOR_STATE "strip1/color/status" -// FastLED -// TODO : essayer, devrait limiter le flikering -//#define FASTLED_ALLOW_INTERRUPTS 0 -#define FASTLED_ESP8266_NODEMCU_PIN_ORDER - void setupWifi(); void testConnectMQTT(); void callbackMQTT(char* topic, byte* payload, unsigned int length); @@ -46,3 +44,129 @@ void ledBlackAll(); void ledCylon(); void ledError(); void ledFullColor(); +///////////////////////////////// ColorPalette +// This example shows several ways to set up and use 'palettes' of colors +// with FastLED. +// +// These compact palettes provide an easy way to re-colorize your +// animation on the fly, quickly, easily, and with low overhead. +// +// USING palettes is MUCH simpler in practice than in theory, so first just +// run this sketch, and watch the pretty lights as you then read through +// the code. Although this sketch has eight (or more) different color schemes, +// the entire sketch compiles down to about 6.5K on AVR. +// +// FastLED provides a few pre-configured color palettes, and makes it +// extremely easy to make up your own color schemes with palettes. +// +// Some notes on the more abstract 'theory and practice' of +// FastLED compact palettes are at the bottom of this file. +CRGBPalette16 currentPalette; +TBlendType currentBlending; + +extern CRGBPalette16 myRedWhiteBluePalette; +extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM; + +// This example shows how to set up a static color palette +// which is stored in PROGMEM (flash), which is almost always more +// plentiful than RAM. A static PROGMEM palette like this +// takes up 64 bytes of flash. +const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM = +{ + CRGB::Red, + CRGB::Gray, // 'white' is too bright compared to red and blue + CRGB::Blue, + CRGB::Black, + + CRGB::Red, + CRGB::Gray, + CRGB::Blue, + CRGB::Black, + + CRGB::Red, + CRGB::Red, + CRGB::Gray, + CRGB::Gray, + CRGB::Blue, + CRGB::Blue, + CRGB::Black, + CRGB::Black +}; + +void ledColorPattern(); +void FillLEDsFromPaletteColors(uint8_t colorIndex); +void ChangePalettePeriodically(); +void SetupTotallyRandomPalette(); +void SetupBlackAndWhiteStripedPalette(); +void SetupPurpleAndGreenPalette(); +//////////////////////////////////////////////// ColorTemperature +// THIS EXAMPLE demonstrates the second, "color temperature" control. +// It shows a simple rainbow animation first with one temperature profile, +// and a few seconds later, with a different temperature profile. +// +// The first pixel of the strip will show the color temperature. +// +// HELPFUL HINTS for "seeing" the effect in this demo: +// * Don't look directly at the LED pixels. Shine the LEDs aganst +// a white wall, table, or piece of paper, and look at the reflected light. +// +// * If you watch it for a bit, and then walk away, and then come back +// to it, you'll probably be able to "see" whether it's currently using +// the 'redder' or the 'bluer' temperature profile, even not counting +// the lowest 'indicator' pixel. +// +// +// FastLED provides these pre-conigured incandescent color profiles: +// Candle, Tungsten40W, Tungsten100W, Halogen, CarbonArc, +// HighNoonSun, DirectSunlight, OvercastSky, ClearBlueSky, +// FastLED provides these pre-configured gaseous-light color profiles: +// WarmFluorescent, StandardFluorescent, CoolWhiteFluorescent, +// FullSpectrumFluorescent, GrowLightFluorescent, BlackLightFluorescent, +// MercuryVapor, SodiumVapor, MetalHalide, HighPressureSodium, +// FastLED also provides an "Uncorrected temperature" profile +// UncorrectedTemperature; + +#define TEMPERATURE_1 Tungsten100W +#define TEMPERATURE_2 OvercastSky +// How many seconds to show each temperature before switching +#define DISPLAYTIME 20 +// How many seconds to show black between switches +#define BLACKTIME 3 +void colorTemp(); +///////////////////////////////////////////////Fire202 +bool gReverseDirection = false; +// This basic one-dimensional 'fire' simulation works roughly as follows: +// There's a underlying array of 'heat' cells, that model the temperature +// at each point along the line. Every cycle through the simulation, +// four steps are performed: +// 1) All cells cool down a little bit, losing heat to the air +// 2) The heat from each cell drifts 'up' and diffuses a little +// 3) Sometimes randomly new 'sparks' of heat are added at the bottom +// 4) The heat from each cell is rendered as a color into the leds array +// The heat-to-color mapping uses a black-body radiation approximation. +// +// Temperature is in arbitrary units from 0 (cold black) to 255 (white hot). +// +// This simulation scales it self a bit depending on NUM_LEDS; it should look +// "OK" on anywhere from 20 to 100 LEDs without too much tweaking. +// +// I recommend running this simulation at anywhere from 30-100 frames per second, +// meaning an interframe delay of about 10-35 milliseconds. +// +// Looks best on a high-density LED setup (60+ pixels/meter). +// +// +// There are two main parameters you can play with to control the look and +// feel of your fire: COOLING (used in step 1 above), and SPARKING (used +// in step 3 above). +// +// COOLING: How much does the air cool as it rises? +// Less cooling = taller flames. More cooling = shorter flames. +// Default 50, suggested range 20-100 +#define COOLING 55 + +// SPARKING: What chance (out of 255) is there that a new spark will be lit? +// Higher chance = more roaring fire. Lower chance = more flickery fire. +// Default 120, suggested range 50-200. +#define SPARKING 120 +void fire(); From bb900f825a1b89bb38da5ba3b2cc17db8e433561 Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Fri, 10 Mar 2017 14:01:48 +0100 Subject: [PATCH 08/15] l'erreur doit etre rouge --- arduino/mqttfastledmenu/mqttfastledmenu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index 4b7124f..1f9e030 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -234,7 +234,7 @@ void ledError() if ((i % 2) == 0) { leds[i] = CRGB::Black; } else { - leds[i] = color; + leds[i] = CRGB::Red; } } From 304e85295a819c77b408f25e9c341491b713e948 Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Fri, 10 Mar 2017 14:46:47 +0100 Subject: [PATCH 09/15] correction de toute la logique du cylon --- arduino/mqttfastledmenu/mqttfastledmenu.cpp | 42 ++++++++++++--------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index 1f9e030..689bf5a 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -176,22 +176,26 @@ void ledCylon() } if ((i - 2) >= 0) { /* - * Se lit 204/256 d'intensité lumineuse - * àhttps://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors + * Se lit 128/256 d'intensité lumineuse actuelle + * https://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors */ - leds[i - 2] %= 204; + leds[i - 2].fadeLightBy(240); } - if ((i - 2) >= 1) { - leds[i - 2] %= 153; + if ((i - 1) >= 0) { + leds[i - 1].fadeLightBy(200); } leds[i] = color; if ((i + 1) <= LED_NUM) { - leds[i - 2] %= 153; + leds[i + 1] = color; + // Je suis volontairement un peu moins puissant sur l'avant + // pour donner un effet de trainée sur l'arrière + leds[i + 1].fadeLightBy(220); } if ((i + 2) <= LED_NUM) { - leds[i - 2] %= 204; + leds[i + 2] = color; + leds[i + 2].fadeLightBy(240); } FastLED.delay(1000 / speed); @@ -201,27 +205,29 @@ void ledCylon() for(int i = LED_NUM - 1; i > 0; i--) { client.loop(); - if ((i - 2) >= 0) { - /* - * Se lit 204/256 d'intensité lumineuse - * àhttps://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors - */ - leds[i - 2] %= 204; + if (ledEffect != LED_EFFECT_CYLON) { + return; } - if ((i - 2) >= 1) { - leds[i - 2] %= 153; + + if ((i - 2) >= 0) { + leds[i - 2] = color; + leds[i - 2].fadeLightBy(240); + } + if ((i - 1) >= 0) { + leds[i - 1] = color; + leds[i - 1].fadeLightBy(220); } leds[i] = color; if ((i + 1) <= LED_NUM) { - leds[i - 2] %= 153; + leds[i + 1].fadeLightBy(200); } if ((i + 2) <= LED_NUM) { - leds[i - 2] %= 204; + leds[i + 2].fadeLightBy(240); } if ((i + 3) <= LED_NUM) { - leds[i - 3] = CRGB::Black; + leds[i + 3] = CRGB::Black; } FastLED.delay(1000 / speed); From 54f902b99ffc3451ec00aa3a5082439af4561a81 Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Fri, 10 Mar 2017 15:27:31 +0100 Subject: [PATCH 10/15] platforio specific --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3647168..f5ecc73 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ .vscode/* arduino/mqttfastledmenu/mqttfastledmenu.h +arduino/.travis.yml +arduino/lib/* + From e9377a2be51b24688deed932ba5cfc7a2524ccf8 Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Sun, 12 Mar 2017 01:28:00 +0100 Subject: [PATCH 11/15] todo deja fait --- arduino/mqttfastledmenu/mqttfastledmenu.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index 689bf5a..1718fc6 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -38,8 +38,6 @@ void setup() client.setServer(MQTT_SERVER, MQTT_PORT); client.setCallback(callbackMQTT); testConnectMQTT(); - // TODO : ne marche pas comme je le désire : - // au boot il prends les params par défaut, j'aimerais ceux de home assistant // LED LEDS.addLeds(leds, LED_NUM).setCorrection(TypicalSMD5050); From 99319782aa89f78f6c20a277292a252b6a4edafb Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Sun, 12 Mar 2017 01:44:34 +0100 Subject: [PATCH 12/15] uniformisation du code --- arduino/mqttfastledmenu/mqttfastledmenu.cpp | 188 ++++++++++---------- 1 file changed, 92 insertions(+), 96 deletions(-) diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index 1718fc6..cb1aa2d 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -24,7 +24,6 @@ WiFiClient espClient; char message_buff[100]; PubSubClient client(espClient); -/////////////////////////////////////////////// void setup() { @@ -55,10 +54,10 @@ void setup() client.loop(); } - //////////////////////////////////////////////// ColorPalette + //////////////////////////////// ColorPalette /////////////////////////////// currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; - ///////////////////////////////////////////////////////////// + //////////////////////////////// ColorPalette /////////////////////////////// Serial.println("End of setup"); } @@ -130,7 +129,6 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length) // Si on ne repasse pas tout à noir, cela peut faire des effets surprenants ledBlackAll(); ledEffect = msgString; - // TODO : a vraiment tester client.publish(MQTT_LED_EFFECT_STATE, message_buff, true); } else if (stopic == MQTT_LED_BRIGHTNESS_COMMAND) { brightness = msgString.toInt(); @@ -157,8 +155,6 @@ void ledBlackAll() FastLED.show(); } -// TODO : faudra sortir toutes ces fonctions dans un autre fichier - void ledCylon() { // Effet cylon : on allume une led, on attends, on eteinds, on passe à la suivante @@ -248,38 +244,42 @@ void ledError() void ledFullColor() { fill_solid(leds, LED_NUM, color); - int breath = (exp(sin(millis() / 2000.0 * PI)) - 0.36787944) * 108.4; + // TODO : il fadrait pas faire 0 -> 255 mais plutot 20 -> brightness + // Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ + // Augmenter 2000 augmente la fréquence (c'est en fait sin((temps / 1000) * Pi/2) + // 0.36787944 ?? censé correspondre au minimum + // 108.4 ?? censé correspondre au maximum + int breath = (exp(sin(millis() / 2000.0 * PI)) - 0.3678794) * 108.4; + Serial.print(breath); + Serial.println(" / 255"); FastLED.setBrightness(breath); FastLED.delay(100 / speed); } -///////////////////////////////// ColorPalette - - +///////////////////// FastLED-3.1.5/examples/ColorPalette ///////////////////// void ledColorPattern() { - ChangePalettePeriodically(); + ChangePalettePeriodically(); - static uint8_t startIndex = 0; - startIndex = startIndex + 1; /* motion speed */ + static uint8_t startIndex = 0; + startIndex = startIndex + 1; /* motion speed */ - FillLEDsFromPaletteColors( startIndex); + FillLEDsFromPaletteColors( startIndex); - FastLED.show(); - FastLED.delay(1000 / speed); + FastLED.show(); + FastLED.delay(1000 / speed); } void FillLEDsFromPaletteColors(uint8_t colorIndex) { - uint8_t brightness = 255; + uint8_t brightness = 255; - for( int i = 0; i < LED_NUM; i++) { - leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending); - colorIndex += 3; - } + for( int i = 0; i < LED_NUM; i++) { + leds[i] = ColorFromPalette(currentPalette, colorIndex, brightness, currentBlending); + colorIndex += 3; + } } - // There are several different palettes of colors demonstrated here. // // FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p, @@ -290,31 +290,31 @@ void FillLEDsFromPaletteColors(uint8_t colorIndex) void ChangePalettePeriodically() { - uint8_t secondHand = (millis() / 1000) % 60; - static uint8_t lastSecond = 99; + uint8_t secondHand = (millis() / 1000) % 60; + static uint8_t lastSecond = 99; - if( lastSecond != secondHand) { - lastSecond = secondHand; - if( secondHand == 0) { currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; } - if( secondHand == 10) { currentPalette = RainbowStripeColors_p; currentBlending = NOBLEND; } - if( secondHand == 15) { currentPalette = RainbowStripeColors_p; currentBlending = LINEARBLEND; } - if( secondHand == 20) { SetupPurpleAndGreenPalette(); currentBlending = LINEARBLEND; } - if( secondHand == 25) { SetupTotallyRandomPalette(); currentBlending = LINEARBLEND; } - if( secondHand == 30) { SetupBlackAndWhiteStripedPalette(); currentBlending = NOBLEND; } - if( secondHand == 35) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; } - if( secondHand == 40) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; } - if( secondHand == 45) { currentPalette = PartyColors_p; currentBlending = LINEARBLEND; } - if( secondHand == 50) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; } - if( secondHand == 55) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; } - } + if( lastSecond != secondHand) { + lastSecond = secondHand; + if (secondHand == 0) { currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; } + if (secondHand == 10) { currentPalette = RainbowStripeColors_p; currentBlending = NOBLEND; } + if (secondHand == 15) { currentPalette = RainbowStripeColors_p; currentBlending = LINEARBLEND; } + if (secondHand == 20) { SetupPurpleAndGreenPalette(); currentBlending = LINEARBLEND; } + if (secondHand == 25) { SetupTotallyRandomPalette(); currentBlending = LINEARBLEND; } + if (secondHand == 30) { SetupBlackAndWhiteStripedPalette(); currentBlending = NOBLEND; } + if (secondHand == 35) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; } + if (secondHand == 40) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; } + if (secondHand == 45) { currentPalette = PartyColors_p; currentBlending = LINEARBLEND; } + if (secondHand == 50) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; } + if (secondHand == 55) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; } + } } // This function fills the palette with totally random colors. void SetupTotallyRandomPalette() { - for( int i = 0; i < 16; i++) { - currentPalette[i] = CHSV( random8(), 255, random8()); - } + for (int i = 0; i < 16; i++) { + currentPalette[i] = CHSV(random8(), 255, random8()); + } } // This function sets up a palette of black and white stripes, @@ -323,100 +323,96 @@ void SetupTotallyRandomPalette() // to set them up. void SetupBlackAndWhiteStripedPalette() { - // 'black out' all 16 palette entries... - fill_solid( currentPalette, 16, CRGB::Black); - // and set every fourth one to white. - currentPalette[0] = CRGB::White; - currentPalette[4] = CRGB::White; - currentPalette[8] = CRGB::White; - currentPalette[12] = CRGB::White; - + // 'black out' all 16 palette entries... + fill_solid(currentPalette, 16, CRGB::Black); + // and set every fourth one to white. + currentPalette[0] = CRGB::White; + currentPalette[4] = CRGB::White; + currentPalette[8] = CRGB::White; + currentPalette[12] = CRGB::White; } // This function sets up a palette of purple and green stripes. void SetupPurpleAndGreenPalette() { - CRGB purple = CHSV( HUE_PURPLE, 255, 255); - CRGB green = CHSV( HUE_GREEN, 255, 255); - CRGB black = CRGB::Black; + CRGB purple = CHSV(HUE_PURPLE, 255, 255); + CRGB green = CHSV(HUE_GREEN, 255, 255); + CRGB black = CRGB::Black; - currentPalette = CRGBPalette16( - green, green, black, black, - purple, purple, black, black, - green, green, black, black, - purple, purple, black, black ); + currentPalette = CRGBPalette16( + green, green, black, black, + purple, purple, black, black, + green, green, black, black, + purple, purple, black, black + ); } +///////////////////// FastLED-3.1.5/examples/ColorPalette ///////////////////// -////////////////////////////////////////////////////////////////////////////// - - - -//////////////////////////////////////////////// ColorTemperature +/////////////////// FastLED-3.1.5/examples/ColorTemperature /////////////////// void colorTemp() { // draw a generic, no-name rainbow static uint8_t starthue = 0; - fill_rainbow( leds + 5, LED_NUM - 5, --starthue, 20); + fill_rainbow(leds + 5, LED_NUM - 5, --starthue, 20); // Choose which 'color temperature' profile to enable. uint8_t secs = (millis() / 1000) % (DISPLAYTIME * 2); - if( secs < DISPLAYTIME) { - FastLED.setTemperature( TEMPERATURE_1 ); // first temperature + if (secs < DISPLAYTIME) { + FastLED.setTemperature(TEMPERATURE_1 ); // first temperature leds[0] = TEMPERATURE_1; // show indicator pixel } else { - FastLED.setTemperature( TEMPERATURE_2 ); // second temperature + FastLED.setTemperature(TEMPERATURE_2 ); // second temperature leds[0] = TEMPERATURE_2; // show indicator pixel } // Black out the LEDs for a few secnds between color changes // to let the eyes and brains adjust - if( (secs % DISPLAYTIME) < BLACKTIME) { - memset8( leds, 0, LED_NUM * sizeof(CRGB)); + if((secs % DISPLAYTIME) < BLACKTIME) { + memset8(leds, 0, LED_NUM * sizeof(CRGB)); } FastLED.show(); FastLED.delay(8); } -//////////////////////////////////////////////////////////////////// +/////////////////// FastLED-3.1.5/examples/ColorTemperature /////////////////// - -///////////////////////////////////////////////Fire202 +//////////////////////// FastLED-3.1.5/examples/Fire202 /////////////////////// void fire() { -// 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]); + int pixelnumber; + if (gReverseDirection) { + pixelnumber = (LED_NUM - 1) - j; + } else { + pixelnumber = j; } + leds[pixelnumber] = color; + } - FastLED.delay(1000 / speed); + FastLED.delay(1000 / speed); } -///////////////////////////////////////////// +//////////////////////// FastLED-3.1.5/examples/Fire202 /////////////////////// void loop() { // MQTT From cec7d7140e69e3b305bc9fe9fbb4e012a8ccaacc Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Sun, 12 Mar 2017 01:45:47 +0100 Subject: [PATCH 13/15] =?UTF-8?q?plateformio=20d=C3=A8s=20la=20racine=20du?= =?UTF-8?q?=20projet=20en=20fait?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 9 ++++++--- arduino/.gitignore | 4 ---- arduino/platformio.ini => platformio.ini | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) delete mode 100644 arduino/.gitignore rename arduino/platformio.ini => platformio.ini (93%) diff --git a/.gitignore b/.gitignore index f5ecc73..b678c9b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ .vscode/* arduino/mqttfastledmenu/mqttfastledmenu.h -arduino/.travis.yml -arduino/lib/* - +.travis.yml +lib/* +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json diff --git a/arduino/.gitignore b/arduino/.gitignore deleted file mode 100644 index 5dac9f5..0000000 --- a/arduino/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.pioenvs -.piolibdeps -.clang_complete -.gcc-flags.json diff --git a/arduino/platformio.ini b/platformio.ini similarity index 93% rename from arduino/platformio.ini rename to platformio.ini index deddd6f..427912b 100644 --- a/arduino/platformio.ini +++ b/platformio.ini @@ -14,5 +14,5 @@ board=nodemcuv2 framework=arduino [platformio] -src_dir=mqttfastledmenu +src_dir=arduino/mqttfastledmenu lib_dir=/home/jcabillot/Arduino/libraries From 04e2bf3de1b03f500dee311869386b31c1b2820b Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Sun, 12 Mar 2017 01:52:13 +0100 Subject: [PATCH 14/15] indentation + doc --- arduino/mqttfastledmenu/mqttfastledmenu.cpp | 211 ++++++++++---------- 1 file changed, 110 insertions(+), 101 deletions(-) diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index cb1aa2d..cf9bb72 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -14,7 +14,7 @@ int brightness = LED_BRIGHTNESS_DEFAULT; int color = LED_COLOR_DEFAULT; int speed = LED_SPEED_DEFAULT; CRGB leds[LED_NUM]; -String ledEffect = LED_EFFECT_CYLON; +String ledEffect = LED_EFFECT_ERROR; boolean ledState = false; // WIFI @@ -45,21 +45,21 @@ void setup() Serial.println("Ready"); /* MQTT - * Il est important de faire un loop avant toute chose, - * afin de récupérer les valeurs provenant du broker mqtt - * et pas démarrer avec de vieilles infos. - */ - for (short int i = 0; i < 10; i++) { - delay(200); - client.loop(); - } + * Il est important de faire un loop avant toute chose, + * afin de récupérer les valeurs provenant du broker mqtt + * et pas démarrer avec de vieilles infos. + */ + for (short int i = 0; i < 10; i++) { + delay(200); + client.loop(); + } - //////////////////////////////// ColorPalette /////////////////////////////// - currentPalette = RainbowColors_p; - currentBlending = LINEARBLEND; - //////////////////////////////// ColorPalette /////////////////////////////// + //////////////////////////////// ColorPalette /////////////////////////////// + currentPalette = RainbowColors_p; + currentBlending = LINEARBLEND; + //////////////////////////////// ColorPalette /////////////////////////////// - Serial.println("End of setup"); + Serial.println("End of setup"); } // WIFI @@ -149,111 +149,120 @@ void callbackMQTT(char* topic, byte* payload, unsigned int length) } // LED +/** +* Coupe tout le strip de led. +*/ void ledBlackAll() { - FastLED.clear(); - FastLED.show(); + FastLED.clear(); + FastLED.show(); } +/** +* Effet Cylon : défilement d'une simple led sur le strip aller/retour. +* Pour faire plus sympas on ajoute une lueur autour, avec une lumière atténué. +*/ void ledCylon() { - // Effet cylon : on allume une led, on attends, on eteinds, on passe à la suivante - for(int i = 0; i < LED_NUM; i++) { - client.loop(); + for(int i = 0; i < LED_NUM; i++) { + client.loop(); - if (ledEffect != LED_EFFECT_CYLON) { - return; - } - - if ((i - 3) >= 0) { - leds[i - 3] = CRGB::Black; - } - if ((i - 2) >= 0) { - /* - * Se lit 128/256 d'intensité lumineuse actuelle - * https://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors - */ - leds[i - 2].fadeLightBy(240); - } - if ((i - 1) >= 0) { - leds[i - 1].fadeLightBy(200); - } - - leds[i] = color; - - if ((i + 1) <= LED_NUM) { - leds[i + 1] = color; - // Je suis volontairement un peu moins puissant sur l'avant - // pour donner un effet de trainée sur l'arrière - leds[i + 1].fadeLightBy(220); - } - if ((i + 2) <= LED_NUM) { - leds[i + 2] = color; - leds[i + 2].fadeLightBy(240); - } - - FastLED.delay(1000 / speed); + if (ledEffect != LED_EFFECT_CYLON) { + return; } - // led[0] et led[255] sont gérées par la loop précédante - for(int i = LED_NUM - 1; i > 0; i--) { - client.loop(); - - if (ledEffect != LED_EFFECT_CYLON) { - return; - } - - if ((i - 2) >= 0) { - leds[i - 2] = color; - leds[i - 2].fadeLightBy(240); - } - if ((i - 1) >= 0) { - leds[i - 1] = color; - leds[i - 1].fadeLightBy(220); - } - - leds[i] = color; - - if ((i + 1) <= LED_NUM) { - leds[i + 1].fadeLightBy(200); - } - if ((i + 2) <= LED_NUM) { - leds[i + 2].fadeLightBy(240); - } - if ((i + 3) <= LED_NUM) { - leds[i + 3] = CRGB::Black; - } - - FastLED.delay(1000 / speed); + if ((i - 3) >= 0) { + leds[i - 3] = CRGB::Black; + } + if ((i - 2) >= 0) { + /* + * Se lit 128/256 d'intensité lumineuse actuelle + * https://github.com/FastLED/FastLED/wiki/Pixel-reference#dimming-and-brightening-colors + */ + leds[i - 2].fadeLightBy(240); + } + if ((i - 1) >= 0) { + leds[i - 1].fadeLightBy(200); } -} -void ledError() -{ - for(int i = 0; i < LED_NUM; i++) { - if ((i % 2) == 0) { - leds[i] = CRGB::Black; - } else { - leds[i] = CRGB::Red; - } + leds[i] = color; + + if ((i + 1) <= LED_NUM) { + leds[i + 1] = color; + // Je suis volontairement un peu moins puissant sur l'avant + // pour donner un effet de trainée sur l'arrière + leds[i + 1].fadeLightBy(220); + } + if ((i + 2) <= LED_NUM) { + leds[i + 2] = color; + leds[i + 2].fadeLightBy(240); } FastLED.delay(1000 / speed); + } + + // led[0] et led[255] sont gérées par la loop précédante + for(int i = LED_NUM - 1; i > 0; i--) { + client.loop(); + + if (ledEffect != LED_EFFECT_CYLON) { + return; + } + + if ((i - 2) >= 0) { + leds[i - 2] = color; + leds[i - 2].fadeLightBy(240); + } + if ((i - 1) >= 0) { + leds[i - 1] = color; + leds[i - 1].fadeLightBy(220); + } + + leds[i] = color; + + if ((i + 1) <= LED_NUM) { + leds[i + 1].fadeLightBy(200); + } + if ((i + 2) <= LED_NUM) { + leds[i + 2].fadeLightBy(240); + } + if ((i + 3) <= LED_NUM) { + leds[i + 3] = CRGB::Black; + } + + FastLED.delay(1000 / speed); + } +} + +/** + * Utilise pour indiquer une erreur sur la reception de l'effet. + */ +void ledError() +{ + for(int i = 0; i < LED_NUM; i++) { + if ((i % 2) == 0) { + leds[i] = CRGB::Black; + } else { + leds[i] = CRGB::Red; + } + } + + FastLED.delay(1000 / speed); } void ledFullColor() { - fill_solid(leds, LED_NUM, color); - // TODO : il fadrait pas faire 0 -> 255 mais plutot 20 -> brightness - // Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ - // Augmenter 2000 augmente la fréquence (c'est en fait sin((temps / 1000) * Pi/2) - // 0.36787944 ?? censé correspondre au minimum - // 108.4 ?? censé correspondre au maximum - int breath = (exp(sin(millis() / 2000.0 * PI)) - 0.3678794) * 108.4; - Serial.print(breath); - Serial.println(" / 255"); - FastLED.setBrightness(breath); - FastLED.delay(100 / speed); + fill_solid(leds, LED_NUM, color); + // TODO : il fadrait pas faire 0 -> 255 mais plutot 20 -> brightness + // Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ + // Augmenter 2000 augmente la fréquence (c'est en fait sin((temps / 1000) * Pi/2) + // 0.36787944 ?? censé correspondre au minimum + // 108.4 ?? censé correspondre au maximum + int breath = (exp(sin(millis() / 2000.0 * PI)) - 0.3678794) * 108.4; + Serial.print(breath); + Serial.println(" / 255"); + FastLED.setBrightness(breath); + FastLED.delay(100 / speed); } ///////////////////// FastLED-3.1.5/examples/ColorPalette ///////////////////// From cb79045c3107ec3c74086bdb9e54ed4e8fdbbc5e Mon Sep 17 00:00:00 2001 From: Julien Cabillot Date: Sun, 12 Mar 2017 01:59:00 +0100 Subject: [PATCH 15/15] indentation + doc --- arduino/mqttfastledmenu/mqttfastledmenu.cpp | 22 ++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/arduino/mqttfastledmenu/mqttfastledmenu.cpp b/arduino/mqttfastledmenu/mqttfastledmenu.cpp index cf9bb72..452d08f 100644 --- a/arduino/mqttfastledmenu/mqttfastledmenu.cpp +++ b/arduino/mqttfastledmenu/mqttfastledmenu.cpp @@ -239,7 +239,7 @@ void ledCylon() */ void ledError() { - for(int i = 0; i < LED_NUM; i++) { + for (int i = 0; i < LED_NUM; i++) { if ((i % 2) == 0) { leds[i] = CRGB::Black; } else { @@ -250,10 +250,15 @@ void ledError() FastLED.delay(1000 / speed); } +/** + * Affiche une couleur de manière uniforme sur le strip. + * Pour éviter un éclairage basique, on applique un breath qui permet + * de faire respirer la couleur (brightness). + */ void ledFullColor() { fill_solid(leds, LED_NUM, color); - // TODO : il fadrait pas faire 0 -> 255 mais plutot 20 -> brightness + // TODO : il fadrait pas faire 0 -> 255 mais plutot 20 (ou plus) -> brightness // Source : http://sean.voisen.org/blog/2011/10/breathing-led-with-arduino/ // Augmenter 2000 augmente la fréquence (c'est en fait sin((temps / 1000) * Pi/2) // 0.36787944 ?? censé correspondre au minimum @@ -273,9 +278,8 @@ void ledColorPattern() static uint8_t startIndex = 0; startIndex = startIndex + 1; /* motion speed */ - FillLEDsFromPaletteColors( startIndex); + FillLEDsFromPaletteColors(startIndex); - FastLED.show(); FastLED.delay(1000 / speed); } @@ -284,7 +288,12 @@ void FillLEDsFromPaletteColors(uint8_t colorIndex) uint8_t brightness = 255; for( int i = 0; i < LED_NUM; i++) { - leds[i] = ColorFromPalette(currentPalette, colorIndex, brightness, currentBlending); + leds[i] = ColorFromPalette( + currentPalette, + colorIndex, + brightness, + currentBlending + ); colorIndex += 3; } } @@ -296,7 +305,6 @@ void FillLEDsFromPaletteColors(uint8_t colorIndex) // // Additionally, you can manually define your own color palettes, or you can write // code that creates color palettes on the fly. All are shown here. - void ChangePalettePeriodically() { uint8_t secondHand = (millis() / 1000) % 60; @@ -345,7 +353,7 @@ void SetupBlackAndWhiteStripedPalette() void SetupPurpleAndGreenPalette() { CRGB purple = CHSV(HUE_PURPLE, 255, 255); - CRGB green = CHSV(HUE_GREEN, 255, 255); + CRGB green = CHSV(HUE_GREEN, 255, 255); CRGB black = CRGB::Black; currentPalette = CRGBPalette16(