Documentation ¶
Index ¶
- Constants
- Variables
- func LED(ch uint8) (ONL, ONH, OFFL, OFFH uint8)
- type Dev
- func (d Dev) Configure(cfg PWMConfig) error
- func (d Dev) IsConnected() error
- func (d Dev) Set(channel uint8, on uint32)
- func (d Dev) SetAI(ai bool) error
- func (d Dev) SetAll(on uint32)
- func (d Dev) SetDrive(outdrv bool) error
- func (d Dev) SetInverting(_ uint8, inverting bool) error
- func (d Dev) SetPeriod(period uint64) error
- func (d Dev) SetPhased(channel uint8, on, off uint32)
- func (d Dev) Sleep(sleepEnabled bool) error
- func (d Dev) Top() uint32
- type DevBuffered
- type PWMConfig
Constants ¶
const ( I2CSWRSTADR = 0x0 PCA9685SWRSTBYTE = 0b0000_0110 // 0x06 )
Software reset addresses for generic i2c implementation and PCA specific SWRST. See section 7.6
const ( SUBADR1 uint8 = 0x2 SUBADR2 uint8 = 0x3 SUBADR3 uint8 = 0x4 MODE1 uint8 = 0x0 MODE2 uint8 = 0x1 ALLCALLADR uint8 = 0x05 SWRESET uint8 = 0b0000_0011 // Start of LED registries. corresponds to LED0_ON_L register. // Use LED function to get registries of a specific PWM channel register. LEDSTART = 0x06 )
Registries with nomenclature as seen in manual
const ( RESET byte = 0b1000_0000 EXTCLK byte = 0b0100_0000 AI byte = 0b0010_0000 SLEEP byte = 0b0001_0000 )
MODE1
const ( OUTDRV = 1 << 2 INVRT = 1 << 4 )
MODE2
const ( // ALLLED is channel that selects registries to control all leds. Use with function LED ALLLED = 0xfa // PRESCALE Prescaling byte PRESCALE byte = 0xFE )
Variables ¶
var ( ErrInvalidMode1 = errors.New("pca9685: data read from MODE1 not valid") ErrBadPeriod = errors.New("pca9685: period must be in range 1..25ms") )
Functions ¶
func LED ¶
LED channels from 0-15. Returns 4 registries associated with the channel PWM signal. Channel 250 (0xFA) gives ALL_LED registers. The L suffix represents the 8 LSB of 12 bit timing, the H suffix represents the 4 MSB of the timing. This way you have 0-4095 timing options. ON or OFF will be a number between these two or will be simply ON or OFF (fifth bit of H registry).
The SetPWM implementation in this library does not do phase-shifting so OFF will always happen at time stamp 0. ON will solely decide duty cycle.
Types ¶
type Dev ¶
type Dev struct {
// contains filtered or unexported fields
}
Dev is a handle to the PCA9685 device given an address (usually 0x47) and an i2c bus.
func (Dev) Configure ¶
Configure enables autoincrement, sets all PWM signals to logic low (Ground) and finally sets the Period.
func (Dev) IsConnected ¶
IsConnected returns error if read fails or if driver suspects device is not connected.
func (Dev) Set ¶
Set sets the `on` value of a PWM channel in the range [0..15]. Max value `on` can take is 4095. Example:
d.Set(1, d.Top()/4)
sets the dutycycle of second (LED1) channel to 25%.
func (Dev) SetAI ¶
SetAI enables or disables autoincrement feature on device. Useful for writing to many consecutive registers in one shot.
func (Dev) SetAll ¶
SetAll sets all PWM signals to a ON value. Equivalent of calling
Dev.Set(pca9685.ALLLED, value)
func (Dev) SetDrive ¶
SetDrive configures PWM output connection in MODE2 register.
false: The 16 LEDn outputs are configured with an open-drain structure. true: The 16 LEDn outputs are configured with a totem pole structure.
func (Dev) SetInverting ¶
SetInverting inverts ALL PCA9685 PWMs. The channel argument merely implements PWM interface.
Without inverting, a 25% duty cycle would mean the output is high for 25% of the time and low for the rest. Inverting flips the output as if a NOT gate was placed at the output, meaning that the output would be 25% low and 75% high with a duty cycle of 25%.
func (Dev) SetPeriod ¶
SetPeriod updates the period of this PWM integrated circuit in nanoseconds. To set a particular frequency, use the following formula:
period = 1e9 / frequency
In the equation above frequency is in Hertz.
If you use a period of 0, a period that works well for LEDs will be picked.
PCA9685 accepts frequencies inbetween [40..1000 Hz], or expressed as a period [1..25ms].
func (Dev) SetPhased ¶
SetPhased sets PWM on and off mark. The ON time, which is programmable, will be the time the LED output will be asserted and the OFF time, which is also programmable, will be the time when the LED output will be negated. In this way, the phase shift becomes completely programmable. The resolution for the phase shift is 1⁄4096 of the target frequency.
type DevBuffered ¶
type DevBuffered struct { Dev // contains filtered or unexported fields }
DevBuffered provides a way of performing one-shot writes on all PWM signals. This is useful when working with systems which require as little as possible I/O overhead.
func NewBuffered ¶
func NewBuffered(bus drivers.I2C, addr uint8) *DevBuffered
New creates a new instance of a PCA9685 device. It performs no IO on the i2c bus.
func (*DevBuffered) PrepPhasedSet ¶
func (b *DevBuffered) PrepPhasedSet(channel uint8, on, off uint32)
PrepPhasedSet prepares a phased PWM value to be written to the channel's register on Update() call.
func (*DevBuffered) PrepSet ¶
func (b *DevBuffered) PrepSet(channel uint8, on uint32)
PrepSet prepares a value to be written to the channel's PWM register on Update() call.
func (*DevBuffered) Update ¶
func (b *DevBuffered) Update() error
Update writes the prepared values to the PWM device registers in one shot.