From 2476cd7bd881857450a7bd171c15bf220d6d0c3a Mon Sep 17 00:00:00 2001 From: Patricio Whittingslow Date: Fri, 25 Feb 2022 10:41:42 -0300 Subject: [PATCH] pca9685: fix on=0 bug Setting on to zero caused PWM signal to be set to high. --- pca9685/pca9685.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pca9685/pca9685.go b/pca9685/pca9685.go index 68b4e61..9940e0d 100644 --- a/pca9685/pca9685.go +++ b/pca9685/pca9685.go @@ -89,18 +89,14 @@ func (d Dev) Top() uint32 { } // 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 (d Dev) Set(channel uint8, on uint32) { - switch { - case on > maxtop: - panic("pca9685: value must be in range 0..4096") - case on == 0: - d.SetPhased(channel, 0, maxtop) - return + if on > maxtop { + panic("pca9685: value must be in range 0..4095") } - d.SetPhased(channel, on, 0) }