From 4dc09f37c9aa8cdea2df39bdee8f632a1b123d4f Mon Sep 17 00:00:00 2001 From: debsahu Date: Thu, 29 Mar 2018 23:49:18 -0400 Subject: [PATCH] Updates * Added support for NeoAnimationFX (USE_NEOANIMATIONFX) * Better scaling for speed --- Arduino/McLighting/McLighting.ino | 21 ++++++++++++++++++++- Arduino/McLighting/definitions.h | 9 +++++++++ Arduino/McLighting/request_handlers.h | 5 +++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Arduino/McLighting/McLighting.ino b/Arduino/McLighting/McLighting.ino index 6a77182..88f2417 100644 --- a/Arduino/McLighting/McLighting.ino +++ b/Arduino/McLighting/McLighting.ino @@ -59,6 +59,25 @@ WebSocketsServer webSocket = WebSocketsServer(81); ESP8266HTTPUpdateServer httpUpdater; #endif +#ifdef USE_NEOANIMATIONFX +// *************************************************************************** +// Load libraries / Instanciate NeoAnimationFX library +// *************************************************************************** +// https://github.com/debsahu/NeoAnimationFX +#include +#define NEOMETHOD NeoPBBGRB800 + +NEOMETHOD neoStrip(NUMLEDS); +NeoAnimationFX strip(neoStrip); + +// Uses Pin RX / GPIO3 (Only pin that is supported, due to hardware limitations) +// NEOMETHOD NeoPBBGRB800 uses GRB config 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEOMETHOD NeoPBBGRB400 uses GRB config 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEOMETHOD NeoPBBRGB800 uses RGB config 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEOMETHOD NeoPBBRGB400 uses RGB config 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +#endif + +#ifdef USE_WS2812FX // *************************************************************************** // Load libraries / Instanciate WS2812FX library // *************************************************************************** @@ -78,7 +97,7 @@ WS2812FX strip = WS2812FX(NUMLEDS, PIN, NEO_GRB + NEO_KHZ800); // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input // and minimize distance between Arduino and first pixel. Avoid connecting // on a live circuit...if you must, connect GND first. - +#endif // *************************************************************************** // Load library "ticker" for blinking status led diff --git a/Arduino/McLighting/definitions.h b/Arduino/McLighting/definitions.h index b2448f5..aab1fbf 100644 --- a/Arduino/McLighting/definitions.h +++ b/Arduino/McLighting/definitions.h @@ -1,3 +1,6 @@ +//#define USE_NEOANIMATIONFX // Uses NeoAnimationFX, PIN is ignored & set to RX/GPIO3 +#define USE_WS2812FX // Uses WS2812FX + // Neopixel #define PIN 14 // PIN (14 / D5) where neopixel / WS2811 strip is attached #define NUMLEDS 300 // Number of leds in the strip @@ -13,6 +16,12 @@ const char HOSTNAME[] = "McLighting01"; // Friedly hostname #define ENABLE_HOMEASSISTANT // If defined, enable Homeassistant integration, ENABLE_MQTT must be active #define ENABLE_BUTTON // If defined, enable button handling code, see: https://github.com/toblum/McLighting/wiki/Button-control +#if defined(USE_NEOANIMATIONFX) and defined(USE_WS2812FX) +#error "Cant have both NeoAnimationFX and WS2812FX enabled. Choose either one." +#endif +#if !defined(USE_NEOANIMATIONFX) and !defined(USE_WS2812FX) +#error "Need to either use NeoAnimationFX and WS2812FX mode." +#endif #if defined(ENABLE_MQTT) and defined(ENABLE_AMQTT) #error "Cant have both PubSubClient and AsyncMQTT enabled. Choose either one." #endif diff --git a/Arduino/McLighting/request_handlers.h b/Arduino/McLighting/request_handlers.h index 56a22dc..9dd3a64 100644 --- a/Arduino/McLighting/request_handlers.h +++ b/Arduino/McLighting/request_handlers.h @@ -51,8 +51,9 @@ void getArgs() { } -long convertSpeed(int mcl_speed) { - long ws2812_speed = mcl_speed * 256; +uint16_t convertSpeed(uint8_t mcl_speed) { + //long ws2812_speed = mcl_speed * 256; + uint16_t ws2812_speed = 61760 * (exp(0.0002336 * mcl_speed) - exp(-0.03181 * mcl_speed)); ws2812_speed = SPEED_MAX - ws2812_speed; if (ws2812_speed < SPEED_MIN) { ws2812_speed = SPEED_MIN;