mirror of
https://github.com/kidoman/embd
synced 2024-12-22 04:40:04 +01:00
pca9685: add SetAnalog method
This commit is contained in:
parent
95b06553e5
commit
6da275f5b4
@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/kid0m4n/go-rpi/i2c"
|
||||
"github.com/kid0m4n/go-rpi/util"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -18,6 +19,9 @@ const (
|
||||
preScaleRegAddr = 0xFE
|
||||
|
||||
pwm0OnLowReg = 0x6
|
||||
|
||||
minAnalogValue = 0
|
||||
maxAnalogValue = 255
|
||||
)
|
||||
|
||||
// PCA9685 represents a PCA9685 PWM generator.
|
||||
@ -154,6 +158,11 @@ func (d *PCA9685) SetMicroseconds(channel, us int) (err error) {
|
||||
return d.SetPwm(channel, 0, offTime)
|
||||
}
|
||||
|
||||
func (d *PCA9685) SetAnalog(channel int, value byte) (err error) {
|
||||
offTime := util.Map(int64(value), minAnalogValue, maxAnalogValue, 0, pwmControlPoints-1)
|
||||
return d.SetPwm(channel, 0, int(offTime))
|
||||
}
|
||||
|
||||
// Close stops the controller and resets mode and pwm controller registers.
|
||||
func (d *PCA9685) Close() (err error) {
|
||||
if err = d.setup(); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user