Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- import time
- GPIO.setmode(GPIO.BCM)
- GPIO.setwarnings(False)
- coil_A_1_pin = 16 # pink
- coil_A_2_pin = 22 # orange
- coil_B_1_pin = 25 # blau
- coil_B_2_pin = 27 # gelb
- coil_C_1_pin = 4 # pink
- coil_C_2_pin = 17 # orange
- coil_D_1_pin = 23 # blau
- coil_D_2_pin = 24 # gelb
- # anpassen, falls andere Sequenz
- StepCount = 4
- Seq = range(0, StepCount)
- Seq[0] = [1,0,0,0]
- Seq[1] = [0,0,1,0]
- Seq[2] = [0,1,0,0]
- Seq[3] = [0,0,0,1]
- GPIO.setup(coil_A_1_pin, GPIO.OUT)
- GPIO.setup(coil_A_2_pin, GPIO.OUT)
- GPIO.setup(coil_B_1_pin, GPIO.OUT)
- GPIO.setup(coil_B_2_pin, GPIO.OUT)
- GPIO.setup(coil_C_1_pin, GPIO.OUT)
- GPIO.setup(coil_C_2_pin, GPIO.OUT)
- GPIO.setup(coil_D_1_pin, GPIO.OUT)
- GPIO.setup(coil_D_2_pin, GPIO.OUT)
- zeita = 1
- zeitb = 0.5
- def setStepX(w1, w2, w3, w4):
- GPIO.output(coil_A_1_pin, w1)
- GPIO.output(coil_A_2_pin, w2)
- GPIO.output(coil_B_1_pin, w3)
- GPIO.output(coil_B_2_pin, w4)
- def setStepY(w5, w6, w7, w8):
- GPIO.output(coil_C_1_pin, w5)
- GPIO.output(coil_C_2_pin, w6)
- GPIO.output(coil_D_1_pin, w7)
- GPIO.output(coil_D_2_pin, w8)
- def forwardX(delay, steps):
- for i in range(steps):
- for j in range(StepCount):
- setStepX(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
- time.sleep(delay)
- def backwardsX(delay, steps):
- for i in range(steps):
- for j in reversed(range(StepCount)):
- setStepX(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
- time.sleep(delay)
- def forwardY(delay, steps):
- for i in range(steps):
- for j in range(StepCount):
- setStepY(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
- time.sleep(delay)
- def backwardsY(delay, steps):
- for i in range(steps):
- for j in reversed(range(StepCount)):
- setStepY(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
- time.sleep(delay)
- if __name__ == '__main__':
- for x in range(1):
- delay = 3
- steps = 55
- forwardX(int(delay) / 1000.0, int(steps))
- time.sleep(zeitb)
- steps = 55
- backwardsX(int(delay) / 1000.0, int(steps))
- time.sleep(zeita)
- for y in range(1):
- delay = 2
- steps = 40
- forwardY(int(delay) / 1000.0, int(steps))
- time.sleep(zeitb)
- steps = 40
- backwardsY(int(delay) / 1000.0, int(steps))
- time.sleep(zeita)
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement