pi_gpiozero_examples/servo.py
2020-11-18 07:48:51 +01:00

30 lines
618 B
Python

from gpiozero import Servo
from time import sleep
# https://gpiozero.readthedocs.io/en/stable/recipes.html#servo
#these pulse-width values come from the elektrobit product description
maxPW=2.1/1000
minPW=0.9/1000
# these values are empirically determined and represent maxima
# 0.3 will turn slow in one direction, -0.5 slow in the other
left = 1
right = -1
stop = -0.2
servo = Servo(
17,
initial_value=None,
min_pulse_width=minPW,
max_pulse_width=maxPW)
while True:
servo.value = left
sleep(1)
servo.value = right
sleep(1)
servo.value = stop
sleep(2)