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 ¶
- Constants
- Variables
- type Arm
- type Client
- type Color
- type Group
- type LED
- type PiGlow
- func (p *PiGlow) Client() *Client
- func (p *PiGlow) Close() error
- func (p *PiGlow) Enable() error
- func (p *PiGlow) Reset() error
- func (p *PiGlow) SetBrightness(leds Set, level uint8) error
- func (p *PiGlow) SetLEDControlRegister(register, enables int) error
- func (p *PiGlow) Setup() error
- func (p *PiGlow) Shutdown() error
- type Radius
- type RadiusRange
- type Range
- type Set
Examples ¶
Constants ¶
const MaxRadius = 5
const NumArms = 3
NumArms holds the number of LED spiral arms in the PiGlow.
const NumLEDs = 18
NumLEDs holds the number of LEDs available.
Variables ¶
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.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
type Color ¶
type Color uint8
Color represents a color of a PiGlow LED.
All the colors of the LEDs. Lower colors are closer to the center of the spiral.
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 ¶
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.
type PiGlow ¶
type PiGlow struct {
// contains filtered or unexported fields
}
PiGlow represents a PiGlow device.
func Open ¶
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 ¶
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 ¶
Close frees the underlying resources. It must be called once the PiGlow is no longer in use.
func (*PiGlow) SetBrightness ¶
SetBrightness sets the brightness of all the LEDs in the given set to the given level.
func (*PiGlow) SetLEDControlRegister ¶
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
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.
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.
