fixed wrong led off/on register setting
This commit is contained in:
12
pca9685.go
12
pca9685.go
@@ -168,13 +168,11 @@ func (p *PCA9685) setAllPwm(on uint16, off uint16) {
|
||||
}
|
||||
|
||||
func (p *PCA9685) setPwm(pwm int, on uint16, off uint16) {
|
||||
onB := byte(on)
|
||||
offB := byte(off)
|
||||
|
||||
p.i2cBus.WriteReg(LED0_ON_L+byte(4)*byte(pwm), []byte{onB & 0xF0})
|
||||
p.i2cBus.WriteReg(LED0_ON_H+byte(4)*byte(pwm), []byte{onB & 0x0F})
|
||||
p.i2cBus.WriteReg(LED0_OFF_L+byte(4)*byte(pwm), []byte{offB & 0xF0})
|
||||
p.i2cBus.WriteReg(LED0_OFF_H+byte(4)*byte(pwm), []byte{offB & 0x0F})
|
||||
p.i2cBus.WriteReg(LED0_ON_H+byte(4)*byte(pwm), []byte{byte(on >> 8)})
|
||||
p.i2cBus.WriteReg(LED0_ON_L+byte(4)*byte(pwm), []byte{byte(on & 0x00FF)})
|
||||
p.i2cBus.WriteReg(LED0_OFF_H+byte(4)*byte(pwm), []byte{byte(off >> 8)})
|
||||
p.i2cBus.WriteReg(LED0_OFF_L+byte(4)*byte(pwm), []byte{byte(off & 0x00FF)})
|
||||
}
|
||||
|
||||
func (pwm *Pwm) setPercentage(percentage float32) error {
|
||||
@@ -183,7 +181,7 @@ func (pwm *Pwm) setPercentage(percentage float32) error {
|
||||
}
|
||||
|
||||
pwm.pca.log.Info(fmt.Sprintf("Setting pwm #%v to %v%% at \"%v\" device.", pwm.pin, percentage, pwm.pca.name))
|
||||
pwm.pca.setPwm(pwm.pin, 0, uint16(percentage*float32(pwm.pca.maxPulse)))
|
||||
pwm.pca.setPwm(pwm.pin, 0, uint16((percentage/100)*float32(pwm.pca.maxPulse)))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user