From 7ee869ce4287e63eda3c100b70856f958ca2583c Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 16 May 2021 18:14:02 +0200 Subject: [PATCH] More robust logic for smooth transients on PCA9685 --- platypush/plugins/pwm/pca9685.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/platypush/plugins/pwm/pca9685.py b/platypush/plugins/pwm/pca9685.py index a19aa3853..ce448a344 100644 --- a/platypush/plugins/pwm/pca9685.py +++ b/platypush/plugins/pwm/pca9685.py @@ -95,15 +95,17 @@ class PwmPca9685Plugin(Plugin): done = True for channel, value in values.items(): - if value == pca.channels[channel].duty_cycle: + if abs(value - pca.channels[channel].duty_cycle) < 2: continue done = False if value > pca.channels[channel].duty_cycle: pca.channels[channel].duty_cycle = min(pca.channels[channel].duty_cycle + step_value, + value, self.MAX_PWM_VALUE) else: pca.channels[channel].duty_cycle = max(pca.channels[channel].duty_cycle - step_value, + value, self.MIN_PWM_VALUE) time.sleep(step_duration)