41 lines
755 B
Python
41 lines
755 B
Python
|
import RPi.GPIO as GPIO
|
||
|
from time import sleep
|
||
|
|
||
|
servoPIN = 5
|
||
|
GPIO.setmode(GPIO.BCM)
|
||
|
GPIO.setup(servoPIN, GPIO.OUT)
|
||
|
|
||
|
pwm = GPIO.PWM(servoPIN, 25000) # GPIO 17 als PWM mit 50Hz
|
||
|
pwm.start(0) # Initialisierung
|
||
|
|
||
|
def SetAngle(angle):
|
||
|
#duty = angle / 18 + 2
|
||
|
duty = angle
|
||
|
|
||
|
if angle == 0:
|
||
|
pwm.stop()
|
||
|
GPIO.output(servoPIN, False)
|
||
|
|
||
|
if angle < 0:
|
||
|
pwm.stop()
|
||
|
sleep(0.01)
|
||
|
GPIO.output(servoPIN, True)
|
||
|
|
||
|
if angle > 0:
|
||
|
pwm.start(0)
|
||
|
pwm.ChangeFrequency(25000)
|
||
|
pwm.ChangeDutyCycle(duty)
|
||
|
#sleep(1)
|
||
|
#GPIO.output(servoPIN, False)
|
||
|
#pwm.ChangeDutyCycle(0)
|
||
|
|
||
|
try:
|
||
|
while True:
|
||
|
winkel = raw_input("Winkel: ")
|
||
|
SetAngle(int(winkel))
|
||
|
|
||
|
except KeyboardInterrupt:
|
||
|
print("Ctl C pressed - ending program")
|
||
|
|
||
|
pwm.stop()
|
||
|
GPIO.cleanup()
|