From 126b70f781405d1ea85830b90b71a0d553580233 Mon Sep 17 00:00:00 2001 From: Thomas Arens Date: Wed, 1 May 2019 03:09:08 +0200 Subject: [PATCH 1/2] Added support for APA102 LEDs. Uncomment "#define USE_APA102" in NbpWrapper.h. Connect clock to GPIO 0 and data to GPIO 2. --- wled00/NpbWrapper.h | 29 +++++++++++++++++++++++++---- wled00/wled05_init.ino | 6 ++++++ wled00/wled09_button.ino | 2 ++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/wled00/NpbWrapper.h b/wled00/NpbWrapper.h index c5b811220..9387054ee 100644 --- a/wled00/NpbWrapper.h +++ b/wled00/NpbWrapper.h @@ -3,8 +3,14 @@ #define NpbWrapper_h //PIN CONFIGURATION +//#define USE_APA102 // Uncomment for using APA102 LEDs. +#ifdef USE_APA102 + #define CLKPIN 0 + #define DATAPIN 2 +#else + #define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended) +#endif #define LEDPIN 2 //strip pin. Any for ESP32, gpio2 or 3 is recommended for ESP8266 (gpio2/3 are labeled D4/RX on NodeMCU and Wemos) -#define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended) #define IR_PIN 4 //infrared pin (-1 to disable) #define RLYPIN 12 //pin for relay, will be set HIGH if LEDs are on (-1 to disable). Also usable for standby leds, triggers,... #define AUXPIN -1 //debug auxiliary output pin (-1 to disable) @@ -17,7 +23,9 @@ #define PIXELMETHOD NeoWs2813Method #else //esp8266 //autoselect the right method depending on strip pin - #if LEDPIN == 2 + #ifdef USE_APA102 + #define PIXELMETHOD DotStarMethod + #elif LEDPIN == 2 #define PIXELMETHOD NeoEsp8266Uart1Ws2813Method //if you get an error here, try to change to NeoEsp8266UartWs2813Method or update Neopixelbus #elif LEDPIN == 3 #define PIXELMETHOD NeoEsp8266Dma800KbpsMethod @@ -29,8 +37,13 @@ //you can now change the color order in the web settings -#define PIXELFEATURE3 NeoGrbFeature -#define PIXELFEATURE4 NeoGrbwFeature +#ifdef USE_APA102 + #define PIXELFEATURE3 DotStarBgrFeature + #define PIXELFEATURE4 DotStarLbgrFeature +#else + #define PIXELFEATURE3 NeoGrbFeature + #define PIXELFEATURE4 NeoGrbwFeature +#endif #include @@ -68,12 +81,20 @@ public: switch (_type) { case NeoPixelType_Grb: + #ifdef USE_APA102 + _pGrb = new NeoPixelBrightnessBus(countPixels, CLKPIN, DATAPIN); + #else _pGrb = new NeoPixelBrightnessBus(countPixels, LEDPIN); + #endif _pGrb->Begin(); break; case NeoPixelType_Grbw: + #ifdef USE_APA102 + _pGrbw = new NeoPixelBrightnessBus(countPixels, CLKPIN, DATAPIN); + #else _pGrbw = new NeoPixelBrightnessBus(countPixels, LEDPIN); + #endif _pGrbw->Begin(); break; } diff --git a/wled00/wled05_init.ino b/wled00/wled05_init.ino index 75818aa38..215b84774 100644 --- a/wled00/wled05_init.ino +++ b/wled00/wled05_init.ino @@ -154,7 +154,9 @@ void beginStrip() strip.setColor(0); strip.setBrightness(255); +#ifdef BTNPIN pinMode(BTNPIN, INPUT_PULLUP); +#endif if (bootPreset>0) applyPreset(bootPreset, turnOnAtBoot, true, true); colorUpdated(0); @@ -170,7 +172,11 @@ void beginStrip() #endif //disable button if it is "pressed" unintentionally +#ifdef BTNPIN if(digitalRead(BTNPIN) == LOW) buttonEnabled = false; +#else + buttonEnabled = false; +#endif } diff --git a/wled00/wled09_button.ino b/wled00/wled09_button.ino index a4e8da23a..b6387b8eb 100644 --- a/wled00/wled09_button.ino +++ b/wled00/wled09_button.ino @@ -16,6 +16,7 @@ void shortPressAction() void handleButton() { +#ifdef BTNPIN if (!buttonEnabled) return; if (digitalRead(BTNPIN) == LOW && !buttonPressedBefore) //pressed @@ -51,6 +52,7 @@ void handleButton() buttonWaitTime = 0; shortPressAction(); } +#endif } void handleIO() From 9b7db548a261935a0ca4cfc19f99dad3520dab8a Mon Sep 17 00:00:00 2001 From: Thomas Arens Date: Wed, 1 May 2019 16:52:22 +0200 Subject: [PATCH 2/2] Only disable the button pin if it conflicts with one of the APA102 pins. --- wled00/NpbWrapper.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wled00/NpbWrapper.h b/wled00/NpbWrapper.h index 9387054ee..0ca8344f0 100644 --- a/wled00/NpbWrapper.h +++ b/wled00/NpbWrapper.h @@ -3,13 +3,16 @@ #define NpbWrapper_h //PIN CONFIGURATION +#define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended) //#define USE_APA102 // Uncomment for using APA102 LEDs. #ifdef USE_APA102 #define CLKPIN 0 #define DATAPIN 2 -#else - #define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended) + #if BTNPIN == CLKPIN || BTNPIN == DATAPIN + #undef BTNPIN // Deactivate button pin if it conflicts with one of the APA102 pins. + #endif #endif + #define LEDPIN 2 //strip pin. Any for ESP32, gpio2 or 3 is recommended for ESP8266 (gpio2/3 are labeled D4/RX on NodeMCU and Wemos) #define IR_PIN 4 //infrared pin (-1 to disable) #define RLYPIN 12 //pin for relay, will be set HIGH if LEDs are on (-1 to disable). Also usable for standby leds, triggers,...