From 3d4d1e3b94a75e344adeb1eb5869d62ebeaffb54 Mon Sep 17 00:00:00 2001 From: Kai Morich Date: Sat, 4 Apr 2026 12:15:02 +0200 Subject: [PATCH 1/3] add function to turn off the servo --- servo.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/servo.py b/servo.py index 3c2df26..0a8d5e9 100644 --- a/servo.py +++ b/servo.py @@ -60,14 +60,22 @@ def pwm(self, pwm): """Set servo pulse width in µs for a 2ms frame. The pulse value is clamped between configured min and max pulse widths. + Use None to turn off the servo. """ - pwm = min(max(pwm, self.min_pulse), self.max_pulse) self._ensure_hw() if self.servo is None: # No hardware available; nothing to do. return - # Convert microseconds in ~2ms frame to 16-bit duty (Raspberry Pi Pico style) - self.servo.duty_u16(int(pwm * 3.2768)) + if pwm == None: + self.servo.duty_u16(0) + else: + pwm = min(max(pwm, self.min_pulse), self.max_pulse) + # Convert microseconds in ~2ms frame to 16-bit duty (Raspberry Pi Pico style) + self.servo.duty_u16(int(pwm * 3.2768)) + + def off(self): + """Turn off the servo.""" + self.pwm(None) def angle(self, angle: float) -> None: """Set servo angle. Values are capped between min_angle and max_angle.""" From f05dcef637c4f0159171af714fde2add15c26488 Mon Sep 17 00:00:00 2001 From: kai-morich Date: Sat, 4 Apr 2026 16:42:37 +0200 Subject: [PATCH 2/3] fix comparison Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- servo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servo.py b/servo.py index 0a8d5e9..82d30ed 100644 --- a/servo.py +++ b/servo.py @@ -66,7 +66,7 @@ def pwm(self, pwm): if self.servo is None: # No hardware available; nothing to do. return - if pwm == None: + if pwm is None: self.servo.duty_u16(0) else: pwm = min(max(pwm, self.min_pulse), self.max_pulse) From ffe97c1bf602accabdcc05722074f98df5f41e7c Mon Sep 17 00:00:00 2001 From: kai-morich Date: Sat, 4 Apr 2026 16:42:49 +0200 Subject: [PATCH 3/3] fix indentation Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- servo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servo.py b/servo.py index 82d30ed..2c75c5b 100644 --- a/servo.py +++ b/servo.py @@ -67,7 +67,7 @@ def pwm(self, pwm): # No hardware available; nothing to do. return if pwm is None: - self.servo.duty_u16(0) + self.servo.duty_u16(0) else: pwm = min(max(pwm, self.min_pulse), self.max_pulse) # Convert microseconds in ~2ms frame to 16-bit duty (Raspberry Pi Pico style)