29 lines
585 B
Python
29 lines
585 B
Python
import RPi.GPIO as GPIO
|
|
from time import sleep
|
|
|
|
servoPIN = 21
|
|
GPIO.setmode(GPIO.BCM)
|
|
GPIO.setup(servoPIN, GPIO.OUT)
|
|
|
|
pwm = GPIO.PWM(servoPIN, 50) # GPIO 17 als PWM mit 50Hz
|
|
pwm.start(0) # Initialisierung
|
|
|
|
def SetAngle(angle):
|
|
duty = angle / 22.5 + 2
|
|
GPIO.output(servoPIN, True)
|
|
pwm.ChangeDutyCycle(duty)
|
|
# pwm.ChangeDutyCycle(angle)
|
|
sleep(1)
|
|
GPIO.output(servoPIN, False)
|
|
pwm.ChangeDutyCycle(0)
|
|
|
|
try:
|
|
while True:
|
|
winkel = raw_input("Winkel: ")
|
|
SetAngle(float(winkel))
|
|
|
|
except KeyboardInterrupt:
|
|
print("Ctl C pressed - ending program")
|
|
|
|
pwm.stop()
|
|
GPIO.cleanup() |