ws2812

package
v0.35.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: BSD-3-Clause Imports: 3 Imported by: 111

Documentation

Overview

Package ws2812 implements a driver for WS2812 and SK6812 RGB LED strips.

On most platforms NewWS2812 uses bit-banging. On RP2040/RP2350 it uses PIO for hardware-timed control.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	Pin machine.Pin
	// contains filtered or unexported fields
}

Device wraps a pin object for an easy driver interface.

func New

func New(pin machine.Pin) Device

deprecated, use NewWS2812 or NewSK6812 depending on which device you want. calls NewWS2812() to avoid breaking everyone's existing code.

func NewSK6812 added in v0.27.0

func NewSK6812(pin machine.Pin) Device

NewSK6812 returns a new SK6812W/RGBW driver (4 channels, GRBW order, 32-bit protocol), for the 3 channels version use NewWS2812 Use this for SK6812W strips that have a dedicated white channel controlled via color.A. It does not touch the pin object: you have to configure it as an output pin before calling this.

func NewWS2812 added in v0.27.0

func NewWS2812(pin machine.Pin) Device

NewWS2812 returns a new WS2812(RGB) driver. On RP2040/RP2350, it uses PIO for hardware-timed control. On other platforms, you must configure the pin as output before calling this.

func (*Device) SetBrightness added in v0.35.0

func (d *Device) SetBrightness(b uint8)

SetBrightness sets the global brightness (0-255).

func (Device) Write

func (d Device) Write(buf []byte) (n int, err error)

Write the raw bitstring out using the WS2812 protocol.

func (Device) WriteByte added in v0.9.0

func (d Device) WriteByte(c byte) error

Send a single byte using the WS2812 protocol.

func (Device) WriteColors

func (d Device) WriteColors(buf []color.RGBA) (err error)

Write the given color slice out using the WS2812 protocol. Colors are sent out in the usual GRB(A) format.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL