-
Notifications
You must be signed in to change notification settings - Fork 0
/
motor.py
executable file
·125 lines (86 loc) · 2.25 KB
/
motor.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
124
# Python Script
import RPi.GPIO as GPIO
enA = 33
enB = 32
in1 = 35
in2 = 37
in3 = 29
in4 = 31
in5 = 11
in6 = 13
in7 = 19
in8 = 21
temp1=1
GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(enA,GPIO.OUT)
GPIO.setup(enB,GPIO.OUT)
GPIO.setup(in1,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(in2,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(in5,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(in6,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(in3,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(in4,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(in7,GPIO.OUT,initial=GPIO.LOW)
GPIO.setup(in8,GPIO.OUT,initial=GPIO.LOW)
pwmA=GPIO.PWM(enA,100)
pwmB=GPIO.PWM(enB,100)
pwmA.start(20)
pwmB.start(20)
pwmA.ChangeDutyCycle(100)
pwmB.ChangeDutyCycle(100)
def front():
GPIO.output(in1,GPIO.LOW)
GPIO.output(in2,GPIO.HIGH)
GPIO.output(in3,GPIO.HIGH)
GPIO.output(in4,GPIO.LOW)
GPIO.output(in5,GPIO.LOW)
GPIO.output(in6,GPIO.HIGH)
GPIO.output(in7,GPIO.HIGH)
GPIO.output(in8,GPIO.LOW)
def stop():
GPIO.output(in1,GPIO.LOW)
GPIO.output(in2,GPIO.LOW)
GPIO.output(in3,GPIO.LOW)
GPIO.output(in4,GPIO.LOW)
GPIO.output(in5,GPIO.LOW)
GPIO.output(in6,GPIO.LOW)
GPIO.output(in7,GPIO.LOW)
GPIO.output(in8,GPIO.LOW)
def back():
GPIO.output(in1,GPIO.HIGH)
GPIO.output(in2,GPIO.LOW)
GPIO.output(in3,GPIO.LOW)
GPIO.output(in4,GPIO.HIGH)
GPIO.output(in5,GPIO.HIGH)
GPIO.output(in6,GPIO.LOW)
GPIO.output(in7,GPIO.LOW)
GPIO.output(in8,GPIO.HIGH)
def left():
GPIO.output(in1,GPIO.LOW)
GPIO.output(in2,GPIO.HIGH)
GPIO.output(in3,GPIO.HIGH)
GPIO.output(in4,GPIO.LOW)
GPIO.output(in5,GPIO.HIGH)
GPIO.output(in6,GPIO.LOW)
GPIO.output(in7,GPIO.LOW)
GPIO.output(in8,GPIO.HIGH)
def right():
GPIO.output(in1,GPIO.HIGH)
GPIO.output(in2,GPIO.LOW)
GPIO.output(in3,GPIO.LOW)
GPIO.output(in4,GPIO.HIGH)
GPIO.output(in5,GPIO.LOW)
GPIO.output(in6,GPIO.HIGH)
GPIO.output(in7,GPIO.HIGH)
GPIO.output(in8,GPIO.LOW)
def speedHigh():
pwmA.ChangeDutyCycle(100)
pwmB.ChangeDutyCycle(100)
def speedMed():
pwmA.ChangeDutyCycle(50)
pwmB.ChangeDutyCycle(50)
def speedLow():
pwmA.ChangeDutyCycle(25)
pwmB.ChangeDutyCycle(25)