ws2811

gabbapeople/christmas-tree/ws2811

Controls WS2812 based LEDs and LED strings
ws2811
@/ws2811
Controls WS2812 based LEDs and LED strings
DIport
Board port number the ws2811 driver is connected to
SIZEnumber
Number of LEDs on the string
Bnumber
LED brightness value in the range [0,100]
ws2811
DI
SIZE
B
DEV
DEV@/ws2811
To use the node in your project you should have the gabbapeople/christmas-tree library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#pragma XOD require "https://github.com/adafruit/Adafruit_NeoPixel"

// Include C++ library:
{{#global}}
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif
{{/global}}


struct State {
    uint8_t mem[sizeof(Adafruit_NeoPixel)];
    uint8_t size;
    Adafruit_NeoPixel* ws2811;
};

struct Type {
    uint8_t size;
    Adafruit_NeoPixel* ws2811;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
   if (!isSettingUp())
        return;

    auto state = getState(ctx);
    state->size = getValue<input_SIZE>(ctx);
    state->ws2811 = new (state->mem) Adafruit_NeoPixel(state->size, getValue<input_DI>(ctx), NEO_GRB + NEO_KHZ800);
    state->ws2811->setBrightness(getValue<input_B>(ctx));
    state->ws2811->begin();
    Type obj = { state->size, state->ws2811 };
    emitValue<output_DEV>(ctx, obj);
}