-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMotorControl.py
123 lines (91 loc) · 1.83 KB
/
MotorControl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import wiringpi
IN1 = 15
IN2 = 16
IN3 = 1
IN4 = 4
IN5 = 5
IN6 = 6
IN7 = 10
IN8 = 11
OUTPUT = 1
caseMap = [
[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]
]
Steps1 = 0
Direction1 = True
Steps2 = 0
Direction2 = True
def setup():
# Serial.begin(9600)
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode(IN1, OUTPUT)
wiringpi.pinMode(IN2, OUTPUT)
wiringpi.pinMode(IN3, OUTPUT)
wiringpi.pinMode(IN4, OUTPUT)
wiringpi.pinMode(IN5, OUTPUT)
wiringpi.pinMode(IN6, OUTPUT)
wiringpi.pinMode(IN7, OUTPUT)
wiringpi.pinMode(IN8, OUTPUT)
def loop():
for i in range(4096):
stepper1(1)
delayMicroseconds(800)
Direction1 = not Direction1
for i in range(4096):
stepper1(1)
delayMicroseconds(800)
for i in range(4096):
stepper2(1)
delayMicroseconds(800)
Direction2 = not Direction2
for i in range(4096):
stepper2(1)
delayMicroseconds(800)
def stepper1(xw):
for x in range(xw):
wiringpi.digitalWrite(IN1, caseMap[Steps1][0])
wiringpi.digitalWrite(IN2, caseMap[Steps1][1])
wiringpi.digitalWrite(IN3, caseMap[Steps1][2])
wiringpi.digitalWrite(IN4, caseMap[Steps1][3])
StepOne1()
def stepper2(xw):
for x in range(xw):
wiringpi.digitalWrite(IN5, caseMap[Steps2][0])
wiringpi.digitalWrite(IN6, caseMap[Steps2][1])
wiringpi.digitalWrite(IN7, caseMap[Steps2][2])
wiringpi.digitalWrite(IN8, caseMap[Steps2][3])
StepOne2()
def StepOne1():
if Direction1:
Steps1 += 1
else:
Steps1 -= 1
if Steps1 > 7:
Steps1 = 0
if Steps1 < 0:
Steps1 = 7
def StepOne2():
if Direction2:
Steps2 += 1
else:
Steps2 -= 1
if Steps2 > 7:
Steps2 = 0
if Steps2 < 0:
Steps2 = 7
def main():
if wiringpi.wiringPiSetup() == -1:
# if the wiringPi initialization fails, print error message
print("setup wiringPi failed !")
return 1
setup()
loop()
return 0
main()