Documentation ¶
Overview ¶
Package apa102 drives a strip of APA102 LEDs connected on a SPI port.
These devices are interesting because they have 2 PWMs: one global of 5 bits of resolution and one per channel of 8 bits of resolution. This means that the dynamic range is of 13 bits.
This driver handles color intensity and temperature correction and uses the full near 8000:1 dynamic range as supported by the device.
Datasheet ¶
https://cpldcpu.files.wordpress.com/2014/08/apa-102c-super-led-specifications-2014-en.pdf
Example ¶
package main import ( "image" "image/color" "log" "periph.io/x/periph/conn/spi/spireg" "periph.io/x/periph/devices/apa102" "periph.io/x/periph/host" ) func main() { // Make sure periph is initialized. if _, err := host.Init(); err != nil { log.Fatal(err) } // Use spireg SPI port registry to find the first available SPI bus. p, err := spireg.Open("") if err != nil { log.Fatal(err) } defer p.Close() // Opens a strip of 150 lights are 50% intensity with color temperature at // 5000 Kelvin. dev, err := apa102.New(p, 150, 127, 5000) if err != nil { log.Fatalf("failed to open apa102: %v", err) } img := image.NewNRGBA(image.Rect(0, 0, dev.Bounds().Dy(), 1)) for x := 0; x < img.Rect.Max.X; x++ { img.SetNRGBA(x, 0, color.NRGBA{uint8(x), uint8(255 - x), 0, 255}) } dev.Draw(dev.Bounds(), img, image.Point{}) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Dev ¶
type Dev struct { Intensity uint8 // Set an intensity between 0 (off) and 255 (full brightness). Temperature uint16 // In Kelvin. // contains filtered or unexported fields }
Dev represents a strip of APA-102 LEDs as a strip connected over a SPI port. It accepts a stream of raw RGB pixels and converts it to the full dynamic range as supported by APA102 protocol (nearly 8000:1 contrast ratio).
Includes intensity and temperature correction.
func New ¶
New returns a strip that communicates over SPI to APA102 LEDs.
The SPI port speed should be high, at least in the Mhz range, as there's 32 bits sent per LED, creating a staggered effect. See https://cpldcpu.wordpress.com/2014/11/30/understanding-the-apa102-superled/
Temperature is in °Kelvin and a reasonable default value is 6500°K.
As per APA102-C spec, the chip's max refresh rate is 400hz. https://en.wikipedia.org/wiki/Flicker_fusion_threshold is a recommended reading.
func (*Dev) ColorModel ¶
ColorModel implements devices.Display. There's no surprise, it is color.NRGBAModel.