• API
• FAQ
• Tools
• Archive
SHARE
TWEET

Untitled

a guest Feb 14th, 2016 134 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 = 16 # pink
7. coil_A_2_pin = 22 # orange
8. coil_B_1_pin = 25 # blau
9. coil_B_2_pin = 27 # gelb
10.
11. coil_C_1_pin = 4  # pink
12. coil_C_2_pin = 17 # orange
13. coil_D_1_pin = 23 # blau
14. coil_D_2_pin = 24 # gelb
15.
16.
17. # anpassen, falls andere Sequenz
18. StepCount = 4
19. Seq = range(0, StepCount)
20. Seq[0] = [1,0,0,0]
21. Seq[1] = [0,0,1,0]
22. Seq[2] = [0,1,0,0]
23. Seq[3] = [0,0,0,1]
24.
25. GPIO.setup(coil_A_1_pin, GPIO.OUT)
26. GPIO.setup(coil_A_2_pin, GPIO.OUT)
27. GPIO.setup(coil_B_1_pin, GPIO.OUT)
28. GPIO.setup(coil_B_2_pin, GPIO.OUT)
29.
30. GPIO.setup(coil_C_1_pin, GPIO.OUT)
31. GPIO.setup(coil_C_2_pin, GPIO.OUT)
32. GPIO.setup(coil_D_1_pin, GPIO.OUT)
33. GPIO.setup(coil_D_2_pin, GPIO.OUT)
34.
35. zeita = 1
36. zeitb = 0.5
37.
38. def setStepX(w1, w2, w3, w4):
39.     GPIO.output(coil_A_1_pin, w1)
40.     GPIO.output(coil_A_2_pin, w2)
41.     GPIO.output(coil_B_1_pin, w3)
42.     GPIO.output(coil_B_2_pin, w4)
43.
44. def setStepY(w5, w6, w7, w8):
45.     GPIO.output(coil_C_1_pin, w5)
46.     GPIO.output(coil_C_2_pin, w6)
47.     GPIO.output(coil_D_1_pin, w7)
48.     GPIO.output(coil_D_2_pin, w8)
49.
50.
51. def forwardX(delay, steps):
52.     for i in range(steps):
53.         for j in range(StepCount):
54.             setStepX(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
55.             time.sleep(delay)
56.
57. def backwardsX(delay, steps):
58.     for i in range(steps):
59.         for j in reversed(range(StepCount)):
60.             setStepX(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
61.             time.sleep(delay)
62.
63. def forwardY(delay, steps):
64.     for i in range(steps):
65.         for j in range(StepCount):
66.             setStepY(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
67.             time.sleep(delay)
68.
69. def backwardsY(delay, steps):
70.     for i in range(steps):
71.         for j in reversed(range(StepCount)):
72.             setStepY(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
73.             time.sleep(delay)
74.
75. if __name__ == '__main__':
76.     for x in range(1):
77.         delay = 3
78.         steps = 55
79.         forwardX(int(delay) / 1000.0, int(steps))
80.         time.sleep(zeitb)
81.
82.         steps = 55
83.         backwardsX(int(delay) / 1000.0, int(steps))
84.         time.sleep(zeita)
85.     for y in range(1):
86.         delay = 2
87.         steps = 40
88.         forwardY(int(delay) / 1000.0, int(steps))
89.         time.sleep(zeitb)
90.         steps = 40
91.         backwardsY(int(delay) / 1000.0, int(steps))
92.         time.sleep(zeita)
93.
94.
95.
96. GPIO.cleanup()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top