pca9685: add SetAnalog method

This commit is contained in:
Karan Misra 2014-01-09 15:48:35 +05:30
parent 95b06553e5
commit 6da275f5b4
1 changed files with 9 additions and 0 deletions

View File

@ -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 {