piglow

package module
v0.0.0-...-f64633d Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: Apache-2.0 Imports: 6 Imported by: 2

README

#PiGlow

GoDoc

Manufacturer info

PiGlow

This package provides an alternative API to that provided by https://godoc.org/github.com/goiot/devices/piglow which aims to make it easier to use without hard-coding maps from LED number to position.

The PiGlow is a small add on board for the Raspberry Pi that provides 18 individually controllable LEDs. This board uses the SN3218 8-bit 18-channel PWM chip to drive 18 surface mount LEDs. Communication is done via I2C over the GPIO header with a bus address of 0x54. Each LED can be set to a PWM value of between 0 and 255.

##Datasheet:

Documentation

Overview

Package piglow implements a driver for the Pimoroni PiGlow.

Example
package main

import (
	"time"

	"github.com/rogpeppe/misc/piglow"
	"golang.org/x/exp/io/i2c"
)

func main() {
	p, err := piglow.Open(&i2c.Devfs{Dev: "/dev/i2c-1"})
	if err != nil {
		panic(err)
	}

	if err := p.Setup(); err != nil {
		panic(err)
	}

	brightness := uint8(0)
	allLEDs := piglow.All.LEDs()
	for i := 0; i < 10; i++ {
		brightness ^= 1
		p.SetBrightness(allLEDs, brightness)
		time.Sleep(300 * time.Millisecond)
	}
}

Index

Examples

Constants

View Source
const MaxRadius = 5
View Source
const NumArms = 3

NumArms holds the number of LED spiral arms in the PiGlow.

View Source
const NumLEDs = 18

NumLEDs holds the number of LEDs available.

Variables

View Source
var All = Range{
	R1: NumLEDs,
}

All defines a Group that holds all the LEDs.

Functions

This section is empty.

Types

type Arm

type Arm uint8

Arm represents one of the three arms of the PiGlow LED spiral. It ranges from 0 to 2.

func (Arm) LEDs

func (a Arm) LEDs() Set

type Client

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

func (*Client) Close

func (c *Client) Close() error

Close closes the given client. All its LEDs will be reset.

func (*Client) SetBrightness

func (c *Client) SetBrightness(leds Set, level uint8) error

SetBrightness sets the brightness of all the LEDs in the given set to the given level.

type Color

type Color uint8

Color represents a color of a PiGlow LED.

const (
	White Color = iota
	Blue
	Green
	Yellow
	Orange
	Red
)

All the colors of the LEDs. Lower colors are closer to the center of the spiral.

func (Color) LEDs

func (col Color) LEDs() Set

LEDs implements Group.LEDs by returning all the LEDs with the given color.

type Group

type Group interface {
	// LEDs returns the set of all the LEDs in the group.
	LEDs() Set
}

Group represents a group of LEDs, such as all the LEDs of a particular color.

func ParseGroup

func ParseGroup(s string) (Group, error)

ParseGroup parses a group from a string. A group can be specified in one of the following forms:

<number> - the LED with the given decimal number (0-17)
<number0>..<number1> - all the LEDs in the half-open range [number0..number1).
arm<number> - the arm with the given number (0-3)
r<number> - the LEDs the given distance from the center (0-6)
r<number0>..r<number0> - all the LEDs in the half-open range of radii [number0..number1)
<color-name> - all the LEDs with the given color
all			- all the LEDs

type LED

type LED int

LED represents one of the 18 PiGlow LEDs. Values range from 0 to 17 - the device LED numbers are one greater than this value because they start numbering from 1.

func (LED) LEDs

func (led LED) LEDs() Set

LEDs implements Group.LEDs by returning a group with a single member containing the given LED.

type PiGlow

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

PiGlow represents a PiGlow device.

func Open

func Open(o driver.Opener) (*PiGlow, error)

Open opens a new PiGlow. A PiGlow must be closed if no longer in use. If the PiGlow has not been powered down since last use, it will be opened with its last programmed state.

func (*PiGlow) Client

func (p *PiGlow) Client() *Client

Client returns a new client instance. Each client has its own virtual set of LEDs - the levels from all current clients will be added to produce the final result.

This is useful when several independent goroutines wish to use the same PiGlow.

The client must be closed after use.

func (*PiGlow) Close

func (p *PiGlow) Close() error

Close frees the underlying resources. It must be called once the PiGlow is no longer in use.

func (*PiGlow) Enable

func (p *PiGlow) Enable() error

Enable enables the PiGlow for normal operations

func (*PiGlow) Reset

func (p *PiGlow) Reset() error

Reset resets the internal registers

func (*PiGlow) SetBrightness

func (p *PiGlow) SetBrightness(leds Set, level uint8) error

SetBrightness sets the brightness of all the LEDs in the given set to the given level.

func (*PiGlow) SetLEDControlRegister

func (p *PiGlow) SetLEDControlRegister(register, enables int) error

SetLEDControlRegister sets the control register 1-3 to the bitmask enables.

bitmask definition:
0 - LED disabled
1 - LED enabled
LED Control Register 1 - LED channel 1  to 6   bits 0-5
LED Control Register 2 - LED channel 7  to 12  bits 0-5
LED Control Register 3 - LED channel 13 to 18  bits 0-5

func (*PiGlow) Setup

func (p *PiGlow) Setup() error

Setup enables normal operations, resets the internal registers, and enables all LED control registers

func (*PiGlow) Shutdown

func (p *PiGlow) Shutdown() error

Shutdown sets the software shutdown mode of the PiGlow

type Radius

type Radius uint8

Radius represents the LEDs a certain distance from the center of the spiral. Zero represents the LEDs closest to the center; 5 represents the LEDs furthest away.

func (Radius) LEDs

func (r Radius) LEDs() Set

type RadiusRange

type RadiusRange struct {
	// R0 holds the start of the range.
	R0 Radius

	// R1 holds one beyond the end of the range.
	// If R1 <= R0, the set is empty.
	R1 Radius
}

RadiusRange represents a range of radii.

func (RadiusRange) LEDs

func (r RadiusRange) LEDs() Set

LEDs implements Group.LEDs by returning all the LEDs in the given radius range.

type Range

type Range struct {
	// R0 holds the start of the range.
	R0 LED
	// R1 holds one beyond the end of the range.
	// If R1 <= R0, the set is empty.
	R1 LED
}

Range represents a numerical range of LEDs.

func (Range) LEDs

func (r Range) LEDs() Set

Range implements Group.LEDs by returning a set of all the LEDs in the range.

type Set

type Set uint32

Set represents a set of LEDs. LED n is represented by the bit 1<<n.

func SetOf

func SetOf(leds ...LED) Set

SetOf returns the set of all the given LEDs.

func (Set) Has

func (s Set) Has(led LED) bool

func (Set) With

func (s Set) With(led LED) Set

func (Set) Without

func (s Set) Without(led LED) Set

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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