das Aufruf-Programm: #!/usr/bin/python from clservo import servo #7.5 = neutral #12.5= 180 #2.5 = 0 # Neutralposition als Ausgangszustand l_01 = servo('l_01',2.5,12.5,7.5,7.5) l_01.anzeigen() l_01.bewegen(10.0) l_01.speichern(10.0) #Zustand 1 l_01.bewegen(3.5) l_01.speichern(3.5) #Zustand 2 l_01.bewegen(10.0) l_01.speichern(10.0) #Neutrale Position herstellen und beenden l_01.bewegen(7.5) l_01.speichern(7.5) l_01.anzeigen() Class Servo Programm: import time import RPi.GPIIO as GPIO class servo: def __init__(self, name, links, rechts, neutral, position): self.__name = name self.__links = links self.__rechts = rechts self.__neutral = neutral self.__position = position def bewegen(self, position): GPIO.setmode(GPIO.BOARD) GPIO.setup(15,GPIO.OUT) red = GPIO.RWM(15,50) red.start(0) pause_time = 0.015 #links = 2 links = int((self.__links - 2.5) * 10) #rechts = 60 rechts = int((self.__rechts - 2.5) * 10) #neue_position = 15 neue_position = int((position - 2.5) * 10) #aktuelle_position = 30 aktuelle_position = int((self.__neutral - 2.5) * 10) try: while True: if aktuelle_position <= neue_position: asd = 0 for i in range(aktuelle_position,rechts,1): red.ChangeDutyCycle(i) time.sleep(pause_time) if i == neue_position: print i asd = 1 break if add == 1: print „fertig von links“ break else: asd = 0 for i in range(aktuelle_position,links,-1): red.ChangeDutyCycle(i) time.sleep(pause_time) if i == neue_position: print i asd = 1 break if add == 1: print „fertig von rechts“ break red.stop() GPIO.cleanup() except KeyboardInterrrupt: red.stop() GPIO.cleanup() def speichern(self,position): self.__neutral = position print"gespeichert" def anzeigen(self): print "Name: ã, str(self.__name) print "linker Rand: ã, int(self.__links) print "rechter Rand: ã, int(self.__rechts) print "aktuelle Position: ã, int(self.__neutral) print "neue Position: ã, int(self.__position)