# Untitled

Mar 8th, 2016
178
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import RPi.GPIO as GPIO
2. import time
3.
4. GPIO.setmode(GPIO.BCM)
5. GPIO.setwarnings(False)
6. coil_A_1_pin = 4 # pink
7. coil_A_2_pin = 17 # orange
8. coil_B_1_pin = 6 # blau
9. coil_B_2_pin = 12 # gelb
10.
11. # anpassen, falls andere Sequenz
12. StepCount = 8
13. Seq = range(0, StepCount)
14. Seq[0] = [0,1,0,0]
15. Seq[1] = [0,1,0,1]
16. Seq[2] = [0,0,0,1]
17. Seq[3] = [1,0,0,1]
18. Seq[4] = [1,0,0,0]
19. Seq[5] = [1,0,1,0]
20. Seq[6] = [0,0,1,0]
21. Seq[7] = [0,1,1,0]
22.
23.
24. GPIO.setup(coil_A_1_pin, GPIO.OUT)
25. GPIO.setup(coil_A_2_pin, GPIO.OUT)
26. GPIO.setup(coil_B_1_pin, GPIO.OUT)
27. GPIO.setup(coil_B_2_pin, GPIO.OUT)
28.
29.
30. def setStep(w1, w2, w3, w4):
31. GPIO.output(coil_A_1_pin, w1)
32. GPIO.output(coil_A_2_pin, w2)
33. GPIO.output(coil_B_1_pin, w3)
34. GPIO.output(coil_B_2_pin, w4)
35.
36. def forward(delay, steps):
37. for i in range(steps):
38. for j in range(StepCount):
39. setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
40. time.sleep(delay)
41.
42. def backwards(delay, steps):
43. for i in range(steps):
44. for j in reversed(range(StepCount)):
45. setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
46. time.sleep(delay)
47.
48. if __name__ == '__main__':
49. while True:
50. delay = raw_input("Zeitverzoegerung (ms)?")
51. steps = raw_input("Wie viele Schritte vorwaerts? ")
52. forward(int(delay) / 1000.0, int(steps))
53. steps = raw_input("Wie viele Schritte rueckwaerts? ")
54. backwards(int(delay) / 1000.0, int(steps))