Skip to content

Instantly share code, notes, and snippets.

@CodeNextAdmin
Forked from CodeNextPaco/servo-input.py
Created October 18, 2021 22:05
Show Gist options
  • Save CodeNextAdmin/18aaf4bc3740ae3b17291bfd3be458ac to your computer and use it in GitHub Desktop.
Save CodeNextAdmin/18aaf4bc3740ae3b17291bfd3be458ac to your computer and use it in GitHub Desktop.
from gpiozero import Servo, AngularServo
from time import sleep
#servo = Servo(21)
servo = AngularServo(21, min_angle=0, max_angle=180, min_pulse_width=0.0006, max_pulse_width=0.0024)
while True:
"""
num = input("Enter a number between -1 and 1")
num = float(num)
if num <= 1 and num >= -1:
servo.value = num
sleep(1)
else:
print("That's not allowed")
"""
v = input("enter a number between 0 and 180 \n")
v = float(v)
print(type(v))
print(servo.angle)
if v<=180 and v >= 0:
servo.angle = v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment