Version: v2.2.0+incompatible Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2018 License: Apache-2.0 Imports: 8 Imported by: 0



Package nrzled is a driver for LEDs ws2811/ws2812/ws2812b and compatible devices like sk6812 and ucs1903 that uses a single wire NRZ encoded communication protocol.

Note that some ICs are 7 bits with the least significant bit ignored, others are using a real 8 bits PWM. The PWM frequency varies across ICs.


This directory contains datasheets for ws2812, ws2812b, ucs190x and various sk6812.

UCS1903 datasheet



This section is empty.


This section is empty.


func NRZ

func NRZ(b byte) uint32

NRZ converts a byte into the MSB-first Non-Return-to-Zero encoded 24 bits.

The upper 8 bits are zeros and shall be ignored.

The Non-return-to-zero protocol is a self-clocking signal that enables one-way communication without the need of a dedicated clock signal, unlike SPI driven LEDs like the apa102.

See for more technical details.


type Dev

type Dev struct {
	// contains filtered or unexported fields

Dev is a handle to the LED strip.

func New

func New(p gpiostream.PinOut, numPixels, hz int, channels int) (*Dev, error)

New opens a handle to a compatible LED strip.

The speed (hz) should either be 800000 for fast ICs and 400000 for the slow ones.

channels should be either 1 (White only), 3 (RGB) or 4 (RGBW). For RGB and RGBW, the encoding is respectively GRB and GRBW.

func (*Dev) Bounds

func (d *Dev) Bounds() image.Rectangle

Bounds implements devices.Display. Min is guaranteed to be {0, 0}.

func (*Dev) ColorModel

func (d *Dev) ColorModel() color.Model

ColorModel implements devices.Display.

It is color.NRGBAModel.

func (*Dev) Draw

func (d *Dev) Draw(r image.Rectangle, src image.Image, sp image.Point)

Draw implements devices.Display.

Using something else than image.NRGBA is 10x slower and is not recommended. When using image.NRGBA, the alpha channel is ignored in RGB mode and used as White channel in RGBW mode.

A back buffer is kept so that partial updates are supported, albeit the full LED strip is updated synchronously.

func (*Dev) Halt

func (d *Dev) Halt() error

Halt turns the lights off.

It doesn't affect the back buffer.

func (*Dev) String

func (d *Dev) String() string

func (*Dev) Write

func (d *Dev) Write(pixels []byte) (int, error)

Write accepts a stream of raw RGB/RGBW pixels and sends it as NRZ encoded stream.

This bypasses the back buffer.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL