Skip to content

Instantly share code, notes, and snippets.

@Aircoookie
Last active May 23, 2023 21:00
Show Gist options
  • Select an option

  • Save Aircoookie/fc0670a077eff1e7cfd4aa707b581214 to your computer and use it in GitHub Desktop.

Select an option

Save Aircoookie/fc0670a077eff1e7cfd4aa707b581214 to your computer and use it in GitHub Desktop.

Revisions

  1. Aircoookie revised this gist Jan 4, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion NpbWrapper.h
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@
    #ifdef WORKAROUND_ESP32_BITBANG
    #define PIXELMETHOD NeoEsp32BitBangWs2813Method
    #else
    #define PIXELMETHOD NeoEsp32RmtWS2813_V3Method
    #define PIXELMETHOD NeoEsp32Rmt0Ws2812xMethod
    #endif
    #else //esp8266
    //you may change to DMA method on pin GPIO3 here
  2. Aircoookie revised this gist Mar 27, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion NpbWrapper.h
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    #define LEDPIN 2 //strip pin. Any for ESP32, gpio2 is recommended for ESP8266
    #define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended)
    #define IR_PIN 4 //infrared pin.
    #define RLYPIN 12 //pin for relay, will be set HIGH if LEDs are on (-1 to disable). Also usable for standby leds, triggers,...
    #define RLYPIN 15 //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)

    #define RLYMDE 1 //mode for relay, 0: LOW if LEDs are on 1: HIGH if LEDs are on
  3. Aircoookie revised this gist Mar 27, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion NpbWrapper.h
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,6 @@
    #define LEDPIN 2 //strip pin. Any for ESP32, gpio2 is recommended for ESP8266
    #define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended)
    #define IR_PIN 4 //infrared pin.
    #define AUXPIN 15 //unused auxiliary output pin
    #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)

  4. Aircoookie revised this gist Mar 27, 2019. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions NpbWrapper.h
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,10 @@
    #define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended)
    #define IR_PIN 4 //infrared pin.
    #define AUXPIN 15 //unused auxiliary output pin
    #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)

    #define RLYMDE 1 //mode for relay, 0: LOW if LEDs are on 1: HIGH if LEDs are on


    //automatically uses the right driver method for each platform
  5. Aircoookie revised this gist Dec 8, 2018. 1 changed file with 7 additions and 9 deletions.
    16 changes: 7 additions & 9 deletions NpbWrapper.h
    Original file line number Diff line number Diff line change
    @@ -7,10 +7,13 @@
    //#define WORKAROUND_ESP32_BITBANG
    //see https://github.com/Aircoookie/WLED/issues/2 for flicker free ESP32 support

    #define LEDPIN 2 //strip pin. Only effective for ESP32, ESP8266 must use gpio2
    //PIN CONFIGURATION
    #define LEDPIN 2 //strip pin. Any for ESP32, gpio2 is recommended for ESP8266
    #define BTNPIN 0 //button pin. Needs to have pullup (gpio0 recommended)
    #define IR_PIN 4 //infrared pin.
    #define AUXPIN 15 //unused auxiliary output pin


    //uncomment this if red and green are swapped
    //#define SWAPRG

    //automatically uses the right driver method for each platform
    #ifdef ARDUINO_ARCH_ESP32
    @@ -25,14 +28,9 @@
    //#define PIXELMETHOD NeoEsp8266Dma800KbpsMethod
    #endif

    //handle swapping Red and Green automatically
    #ifdef SWAPRG
    #define PIXELFEATURE3 NeoRgbFeature
    #define PIXELFEATURE4 NeoRgbwFeature
    #else
    //you can now change the color order in the web settings
    #define PIXELFEATURE3 NeoGrbFeature
    #define PIXELFEATURE4 NeoGrbwFeature
    #endif

    #include <NeoPixelBrightnessBus.h>

  6. Aircoookie revised this gist Oct 17, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions NpbWrapper.h
    Original file line number Diff line number Diff line change
    @@ -126,7 +126,7 @@ class NeoPixelWrapper

    void SetPixelColor(uint16_t indexPixel, RgbColor color)
    {
    setRGBPWM(indexPixel, color.R, color.G, color.B);
    SetRGBPWM(indexPixel, color.R, color.G, color.B);

    switch (_type) {
    case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, color); break;
    @@ -136,7 +136,7 @@ class NeoPixelWrapper

    void SetPixelColor(uint16_t indexPixel, RgbwColor color)
    {
    setRGBPWM(indexPixel, color.R, color.G, color.B);
    SetRGBPWM(indexPixel, color.R, color.G, color.B);

    switch (_type) {
    case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B)); break;
  7. Aircoookie revised this gist Oct 17, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions NpbWrapper.h
    Original file line number Diff line number Diff line change
    @@ -118,9 +118,9 @@ class NeoPixelWrapper
    {
    if (indexPixel == 0) //5050 strip is first pixel
    {
    analogWrite(12, r);
    analogWrite(13, g);
    analogWrite(14, b);
    analogWrite(12, r*4);
    analogWrite(13, g*4);
    analogWrite(14, b*4);
    }
    }

  8. Aircoookie revised this gist Oct 17, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion NpbWrapper.h
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    //MODIFIED to drive 5050 RGB strip via PWM on GPIO 12(R),13(G),14(B)
    //MODIFIED to drive 5050 RGB strip via PWM on GPIO 12(R),13(G),14(B), UNTESTED

    //this code is a modified version of https://github.com/Makuna/NeoPixelBus/issues/103
    #ifndef NpbWrapper_h
  9. Aircoookie created this gist Oct 17, 2018.
    206 changes: 206 additions & 0 deletions NpbWrapper.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,206 @@
    //MODIFIED to drive 5050 RGB strip via PWM on GPIO 12(R),13(G),14(B)

    //this code is a modified version of https://github.com/Makuna/NeoPixelBus/issues/103
    #ifndef NpbWrapper_h
    #define NpbWrapper_h

    //#define WORKAROUND_ESP32_BITBANG
    //see https://github.com/Aircoookie/WLED/issues/2 for flicker free ESP32 support

    #define LEDPIN 2 //strip pin. Only effective for ESP32, ESP8266 must use gpio2

    //uncomment this if red and green are swapped
    //#define SWAPRG

    //automatically uses the right driver method for each platform
    #ifdef ARDUINO_ARCH_ESP32
    #ifdef WORKAROUND_ESP32_BITBANG
    #define PIXELMETHOD NeoEsp32BitBangWs2813Method
    #else
    #define PIXELMETHOD NeoEsp32RmtWS2813_V3Method
    #endif
    #else //esp8266
    //you may change to DMA method on pin GPIO3 here
    #define PIXELMETHOD NeoEsp8266Uart800KbpsMethod
    //#define PIXELMETHOD NeoEsp8266Dma800KbpsMethod
    #endif

    //handle swapping Red and Green automatically
    #ifdef SWAPRG
    #define PIXELFEATURE3 NeoRgbFeature
    #define PIXELFEATURE4 NeoRgbwFeature
    #else
    #define PIXELFEATURE3 NeoGrbFeature
    #define PIXELFEATURE4 NeoGrbwFeature
    #endif

    #include <NeoPixelBrightnessBus.h>

    enum NeoPixelType
    {
    NeoPixelType_None = 0,
    NeoPixelType_Grb = 1,
    NeoPixelType_Grbw = 2,
    NeoPixelType_End = 3
    };

    class NeoPixelWrapper
    {
    public:
    NeoPixelWrapper() :
    // initialize each member to null
    _pGrb(NULL),
    _pGrbw(NULL),
    _type(NeoPixelType_None)
    {

    }

    ~NeoPixelWrapper()
    {
    cleanup();
    }

    void Begin(NeoPixelType type, uint16_t countPixels)
    {
    cleanup();
    _type = type;

    switch (_type) {

    case NeoPixelType_Grb:
    _pGrb = new NeoPixelBrightnessBus<PIXELFEATURE3,PIXELMETHOD>(countPixels, LEDPIN);
    _pGrb->Begin();
    break;

    case NeoPixelType_Grbw:
    _pGrbw = new NeoPixelBrightnessBus<PIXELFEATURE4,PIXELMETHOD>(countPixels, LEDPIN);
    _pGrbw->Begin();
    break;
    }

    //init PWM pins
    pinMode(12, OUTPUT);
    pinMode(13, OUTPUT);
    pinMode(14, OUTPUT);
    }

    void Show()
    {
    #ifdef ARDUINO_ARCH_ESP32
    #ifdef WORKAROUND_ESP32_BITBANG
    delay(1);
    portDISABLE_INTERRUPTS(); //this is a workaround to prevent flickering (see https://github.com/adafruit/Adafruit_NeoPixel/issues/139)
    #endif
    #endif

    switch (_type) {
    case NeoPixelType_Grb: _pGrb->Show(); break;
    case NeoPixelType_Grbw: _pGrbw->Show(); break;
    }

    #ifdef ARDUINO_ARCH_ESP32
    #ifdef WORKAROUND_ESP32_BITBANG
    portENABLE_INTERRUPTS();
    #endif
    #endif
    }

    bool CanShow() const
    {
    switch (_type) {
    case NeoPixelType_Grb: _pGrb->CanShow(); break;
    case NeoPixelType_Grbw: _pGrbw->CanShow(); break;
    }
    }

    void SetRGBPWM(uint16_t indexPixel, uint8_t r, uint8_t g, uint8_t b)
    {
    if (indexPixel == 0) //5050 strip is first pixel
    {
    analogWrite(12, r);
    analogWrite(13, g);
    analogWrite(14, b);
    }
    }

    void SetPixelColor(uint16_t indexPixel, RgbColor color)
    {
    setRGBPWM(indexPixel, color.R, color.G, color.B);

    switch (_type) {
    case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, color); break;
    case NeoPixelType_Grbw:_pGrbw->SetPixelColor(indexPixel, color); break;
    }
    }

    void SetPixelColor(uint16_t indexPixel, RgbwColor color)
    {
    setRGBPWM(indexPixel, color.R, color.G, color.B);

    switch (_type) {
    case NeoPixelType_Grb: _pGrb->SetPixelColor(indexPixel, RgbColor(color.R,color.G,color.B)); break;
    case NeoPixelType_Grbw: _pGrbw->SetPixelColor(indexPixel, color); break;
    }
    }

    void SetBrightness(byte b)
    {
    switch (_type) {
    case NeoPixelType_Grb: _pGrb->SetBrightness(b); break;
    case NeoPixelType_Grbw:_pGrbw->SetBrightness(b); break;
    }
    }

    RgbColor GetPixelColor(uint16_t indexPixel) const
    {
    switch (_type) {
    case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
    case NeoPixelType_Grbw: /*doesn't support it so we don't return it*/ break;
    }
    return 0;
    }

    // NOTE: Due to feature differences, some support RGBW but the method name
    // here needs to be unique, thus GetPixeColorRgbw
    RgbwColor GetPixelColorRgbw(uint16_t indexPixel) const
    {
    switch (_type) {
    case NeoPixelType_Grb: return _pGrb->GetPixelColor(indexPixel); break;
    case NeoPixelType_Grbw: return _pGrbw->GetPixelColor(indexPixel); break;
    }
    return 0;
    }

    void ClearTo(RgbColor color)
    {
    switch (_type) {
    case NeoPixelType_Grb: _pGrb->ClearTo(color); break;
    case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break;
    }
    }

    void ClearTo(RgbwColor color)
    {
    switch (_type) {
    case NeoPixelType_Grb: break;
    case NeoPixelType_Grbw:_pGrbw->ClearTo(color); break;
    }
    }

    private:
    NeoPixelType _type;

    // have a member for every possible type
    NeoPixelBrightnessBus<PIXELFEATURE3,PIXELMETHOD>* _pGrb;
    NeoPixelBrightnessBus<PIXELFEATURE4,PIXELMETHOD>* _pGrbw;

    void cleanup()
    {
    switch (_type) {
    case NeoPixelType_Grb: delete _pGrb ; _pGrb = NULL; break;
    case NeoPixelType_Grbw: delete _pGrbw; _pGrbw = NULL; break;
    }
    }
    };
    #endif