Code:
#Get the GPIO module
import RPi.GPIO as GPIO
#Get the time module
import time
#A routine to control a pair of pins
def ControlAPairOfPins(FirstPin,FirstState,SecondPin,SecondState):
if FirstState == "1":
GPIO.output(int(FirstPin),True)
else:
GPIO.output(int(FirstPin),False)
if SecondState == "1":
GPIO.output(int(SecondPin),True)
else:
GPIO.output(int(SecondPin),False)
#Just retur
return
####Main body of code
#Get rid of warnings
GPIO.setwarnings(False)
#Set the GPIO mode
GPIO.setmode(GPIO.BOARD)
#Set the pins to be outputs
GPIO.setup(19,GPIO.OUT)
GPIO.setup(21,GPIO.OUT)
GPIO.setup(23,GPIO.OUT)
GPIO.setup(24,GPIO.OUT)
while True:
ControlAPairOfPins("19","1","21","0")
ControlAPairOfPins("23","1","24","0")
print "Drehung nach rechts"
time.sleep(1)
ControlAPairOfPins("19","0","21","0")
ControlAPairOfPins("23","0","24","0")
print "Stop"
time.sleep(1)
ControlAPairOfPins("19","0","21","1")
ControlAPairOfPins("23","0","24","1")
print "Drehung nach Links"
time.sleep(1)
ControlAPairOfPins("19","0","21","0")
ControlAPairOfPins("23","0","24","0")
print "Stop"
time.sleep(1)
ControlAPairOfPins("19","1","21","0")
ControlAPairOfPins("23","0","24","1")
print "Geradeaus vorwaerts"
time.sleep(1)
ControlAPairOfPins("19","0","21","0")
ControlAPairOfPins("23","0","24","0")
print "Stop"
time.sleep(1)
ControlAPairOfPins("19","0","21","1")
ControlAPairOfPins("23","1","24","0")
print "Geradeaus rueckwaerts"
time.sleep(1)
ControlAPairOfPins("19","0","21","0")
ControlAPairOfPins("23","0","24","0")
print "Stop"
time.sleep(1)
Nun würde ich gerne die Geschwindigkeit regulieren. Meine Programmierkenntnisse reichen hierzu leider nicht mehr aus. Kann mir bitte jemand dabei helfen das in Python zu programmieren?
Lesezeichen