Code: Alles auswählen
import time
from RPi import GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
control_pins_1 = [12, 15, 13, 11] # rv
control_pins_2 = [37, 35, 33, 31] # rh
control_pins_3 = [18, 22, 24, 26] # lv
control_pins_4 = [40, 38, 36, 32] # lh
for pin in control_pins_1:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, 0)
for pin in control_pins_2:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, 0)
for pin in control_pins_3:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, 0)
for pin in control_pins_4:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, 0)
vorstep_seq = [
[1,0,0,0],
[1,1,0,0],
[0,1,0,0],
[0,1,1,0],
[0,0,1,0],
[0,0,1,1],
[0,0,0,1],
[1,0,0,1]
]
rueckstep_seq = [
[0,0,0,1],
[0,0,1,1],
[0,0,1,0],
[0,1,1,0],
[0,1,0,0],
[1,1,0,0],
[1,0,0,0],
[1,0,0,1]
]
class Rad():
def __init__(self, controlpins, seg, speed):
self.speed = speed
self.controlpins = controlpins
self.seg = seg
def vor(self):
for i in range(200):
for vorstep in range(8):
for pin in range(4):
GPIO.output(self.controlpins[pin], self.seg[vorstep][pin])
time.sleep(0.0009)
def rueck(self):
for i in range(200):
for rueckstep in range(8):
for pin in range(4):
GPIO.output(self.controlpins[pin], self.seg[rueckstep][pin])
time.scleep(0.0009)
def getdata(self):
print('Speed : ', self.speed , ', Pins : ', self.controlpins , ', Seq : ', self.seg)
if __name__ == "__main__":
R1 = Rad(control_pins_1, vorstep_seq, 100)
R2 = Rad(control_pins_2, vorstep_seq, 100)
R3 = Rad(control_pins_3, vorstep_seq, 100)
R4 = Rad(control_pins_4, vorstep_seq, 100)
R1.getdata()
R1.vor()
R2.vor()
R3.vor()
R4.cor()
GPIO.cleanup()