RGB LED strip control with WS2811/WS2812 (a.k.a NeoPixel)

This sketch shows how to control WS2811/WS2812 (also known as NeoPixel) right from Z-Uno pins. There is no Z-Wave communication in this example. You can add a Switch Binary channel to turn your LEDs on off or even a Switch Multilevel to define the current LED mode.
  • Z-Uno board
  • Breadboard
  • NeoPixel strip or ring (like this or this)
  • 1 transistor 2N7000 FET
  • 1 1 kΩ resistor
  • 5 V power supply for the RGB strip
  • 7 wires
The 2N7000 transistor is used to invert the logic of the pin. WS2811 requires very fast communications and Z-Uno uses SPI to send data fast enough. But MOSI ping logic is inverted compared to what WS2811 expects.
Download Fritzing project
/*
 * This sketch shows how to control WS2811/WS2812 (also known as NeoPixel) right from Z-Uno pins.
 * There is no Z-Wave communication in this example.
 * You can add a Switch Binary channel to turn your LEDs on off or even a Switch Multilevel to define the current LED mode.
 * WS2811/WS2812 control pin should be connected to SPI MOSI (pin 2)
 */

#include "ZUNO_NeoPixel.h"

#define MAX_PIXELS 14 // NB! Z-Uno can not control more than 25 WS2811 without harming RF communications
#define PIXEL_SIZE 3  // Three colors per pixel
#define BUFF_SIZE (MAX_PIXELS * PIXEL_SIZE)

byte pixel_buff[BUFF_SIZE];

NeoPixel pixels(pixel_buff, BUFF_SIZE);

void setup() {
  pixels.begin();
}

// An example of a rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  byte i, j;
  for(j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
    for(i = 0; i < MAX_PIXELS; i++) {
      pixels.setPixelColor(i, Wheel(((i * 256 / MAX_PIXELS) + j) & 255));
    }
    pixels.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if (WheelPos < 85) {
    return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if (WheelPos < 170) {
    WheelPos -= 85;
    return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
    WheelPos -= 170;
    return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

void loop() {
  rainbowCycle(5);
}
Download this sketch