Skip to content

Commit

Permalink
Merge pull request #797 from gpiozero/pwm-pulse-width
Browse files Browse the repository at this point in the history
Add pulse_width setter to Servo class
  • Loading branch information
bennuttall committed Sep 17, 2019
2 parents 655be7a + bc58317 commit 201a52f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions gpiozero/output_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1486,13 +1486,13 @@ class Servo(SourceMixin, CompositeDevice):
servo = Servo(17)
servo.value = 0.5
.. note::
To reduce servo jitter, use the pigpio pin driver rather than the default
RPi.GPIO driver (pigpio uses DMA sampling for much more precise edge
timing). See :ref:`changing-pin-factory` for further information.
:type pin: int or str
:param pin:
The GPIO pin that the servo is connected to. See :ref:`pin-numbering`
Expand Down Expand Up @@ -1541,13 +1541,13 @@ def __init__(
),
pin_factory=pin_factory
)

if PiGPIOFactory is None or not isinstance(self.pin_factory, PiGPIOFactory):
warnings.warn(PWMSoftwareFallback(
'To reduce servo jitter, use the pigpio pin factory.'
'See https://gpiozero.readthedocs.io/en/stable/api_output.html#servo for more info'
))

try:
self.value = initial_value
except:
Expand Down Expand Up @@ -1587,6 +1587,10 @@ def pulse_width(self):
else:
return self.pwm_device.pin.state * self.frame_width

@pulse_width.setter
def pulse_width(self, value):
self.pwm_device.pin.state = value / self.frame_width

def min(self):
"""
Set the servo to its minimum position.
Expand Down

0 comments on commit 201a52f

Please sign in to comment.