1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 12:50:19 +01:00

pca9685: add SetAnalog method

This commit is contained in:
Karan Misra 2014-01-09 15:48:35 +05:30
parent 95b06553e5
commit 6da275f5b4

View File

@ -8,6 +8,7 @@ import (
"time" "time"
"github.com/kid0m4n/go-rpi/i2c" "github.com/kid0m4n/go-rpi/i2c"
"github.com/kid0m4n/go-rpi/util"
) )
const ( const (
@ -18,6 +19,9 @@ const (
preScaleRegAddr = 0xFE preScaleRegAddr = 0xFE
pwm0OnLowReg = 0x6 pwm0OnLowReg = 0x6
minAnalogValue = 0
maxAnalogValue = 255
) )
// PCA9685 represents a PCA9685 PWM generator. // 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) 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. // Close stops the controller and resets mode and pwm controller registers.
func (d *PCA9685) Close() (err error) { func (d *PCA9685) Close() (err error) {
if err = d.setup(); err != nil { if err = d.setup(); err != nil {