ws2801

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2019 License: BSD-3-Clause Imports: 5 Imported by: 0

README

GoDoc license

ws2801 - a library to address ws2801 led strips connected via SPI

This package controls ws2801 LED strips connected via SPI.

The library has been tested on a raspberry pi zero w with two different ws2801 LED strips.

License

BSD 3-clause license

Contributions

Contributions / Pull requests are welcome.

Documentation

https://godoc.org/github.com/joernott/ws2801

Usage

Create connection

The LED strip connection is created by using the NewPixels function.

	p,err := ws2801.NewPixels(32) //number of pixels in the strip
	if err !=nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer p.Close()
Set a pixel or a range of pixels to a specific color
	err := p.SetPixel(0, 255, 0, 0)
	err := p.SetPixels(2, 4, 0, 255, 0)
	err := p.SetPixels(6, 8, 0, 0, 255)

The Show function actually transmits the data to the strip. It must be called whenever you want to show your changes:

	err := p.Show()
Clear a pixel or a range of pixels
	err := p.ClearPixel(0)
	err := p.ClearPixels(2, 8)
	err := p.Show()

Use the ws2801tool

The ws2801tool is a small commandline tool to set/clear pixels from the command line.

Build
go get -v github.com/joernott/ws2801tool
Usage

ws2801tool [command]

Available Commands: clear Clears a pixel or a range of pixels help Help about any command set Sets one or more pixels to a specific color

Flags: -h, --help Help for ws2801tool -p, --position int Position of the pixel. -f, --first int Position of the first pixel when defining a range. -l, --last int Position of the last pixel when defining a range. -n, --number_of_leds int Number of LEDs -r, --red uint8 Intensity of the red subpixel -g, --green uint8 Intensity of the green subpixel -b, --blue uint8 Intensity of the blue subpixel

Use "ws2801tool [command] --help" for more information about a command. subcommand is required

Documentation

Overview

Package ws2801 uses periph to access ws2801 LED strips via SPI

This package uses the SPI interface provioded by periph to control a ws2801 LED strip.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pixels

type Pixels struct {
	// contains filtered or unexported fields
}

The Pixels object is the interface to the LED strip.

func NewPixels

func NewPixels(NumLEDs int) (*Pixels, error)

NewPixels creates a new Pixels object.

NumLEDs is the total number of LEDs in the strip.

func (*Pixels) ClearPixel

func (p *Pixels) ClearPixel(Position int) error

ClearPixel sets the color of a pixel to black.

Position is the number of the pixel starting with 0.

func (*Pixels) ClearPixels

func (p *Pixels) ClearPixels(Start int, End int) error

ClearPixels sets the color of a range of pixels.

Start is the position of the first pixel to set. End is the position of the last pixel to set. Red specifies the intensity of the red subpixels. It ranges between 0 and 255. Green specifies the intensity of the green subpixels. It ranges between 0 and 255. Blue specifies the intensity of the blue subpixels. It ranges between 0 and 255.

func (*Pixels) Close

func (p *Pixels) Close()

Close closes the Pixels object and the SPI connection.

func (*Pixels) Count

func (p *Pixels) Count() int

Count returns the number of LEDs of the Pixels object.

func (*Pixels) SetPixel

func (p *Pixels) SetPixel(Position int, Red byte, Green byte, Blue byte) error

SetPixel sets the color of a pixel.

Position is the number of the pixel starting with 0. Red specifies the intensity of the red subpixel. It ranges between 0 and 255. Green specifies the intensity of the green subpixel. It ranges between 0 and 255. Blue specifies the intensity of the blue subpixel. It ranges between 0 and 255.

func (*Pixels) SetPixels

func (p *Pixels) SetPixels(Start int, End int, Red byte, Green byte, Blue byte) error

SetPixels sets the color of a range of pixels.

Start is the position of the first pixel to set. End is the position of the last pixel to set. Red specifies the intensity of the red subpixels. It ranges between 0 and 255. Green specifies the intensity of the green subpixels. It ranges between 0 and 255. Blue specifies the intensity of the blue subpixels. It ranges between 0 and 255.

func (*Pixels) Show

func (p *Pixels) Show() error

Show must be called after any change of pixel colors.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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