Skip to content

Commit 6e89365

Browse files
authored
Create Controlling DC Motors Using Python With a Raspberry Pi
1 parent 5e6f2e2 commit 6e89365

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import RPi.GPIO as GPIO
2+
from time import sleep
3+
4+
GPIO.setmode(GPIO.BOARD)
5+
6+
Motor1A = 16
7+
Motor1B = 18
8+
Motor1E = 22
9+
10+
GPIO.setup(Motor1A,GPIO.OUT)
11+
GPIO.setup(Motor1B,GPIO.OUT)
12+
GPIO.setup(Motor1E,GPIO.OUT)
13+
14+
print "Going forwards"
15+
GPIO.output(Motor1A,GPIO.HIGH)
16+
GPIO.output(Motor1B,GPIO.LOW)
17+
GPIO.output(Motor1E,GPIO.HIGH)
18+
19+
sleep(2)
20+
21+
print "Going backwards"
22+
GPIO.output(Motor1A,GPIO.LOW)
23+
GPIO.output(Motor1B,GPIO.HIGH)
24+
GPIO.output(Motor1E,GPIO.HIGH)
25+
26+
sleep(2)
27+
28+
print "Now stop"
29+
GPIO.output(Motor1E,GPIO.LOW)
30+
31+
GPIO.cleanup()
32+
//CTRL-X then Y followed by Enter to save
33+
//for two motors
34+
35+
import RPi.GPIO as GPIO
36+
from time import sleep
37+
38+
GPIO.setmode(GPIO.BOARD)
39+
40+
Motor1A = 16
41+
Motor1B = 18
42+
Motor1E = 22
43+
44+
Motor2A = 23
45+
Motor2B = 21
46+
Motor2E = 19
47+
48+
GPIO.setup(Motor1A,GPIO.OUT)
49+
GPIO.setup(Motor1B,GPIO.OUT)
50+
GPIO.setup(Motor1E,GPIO.OUT)
51+
52+
GPIO.setup(Motor2A,GPIO.OUT)
53+
GPIO.setup(Motor2B,GPIO.OUT)
54+
GPIO.setup(Motor2E,GPIO.OUT)
55+
56+
print "Going forwards"
57+
GPIO.output(Motor1A,GPIO.HIGH)
58+
GPIO.output(Motor1B,GPIO.LOW)
59+
GPIO.output(Motor1E,GPIO.HIGH)
60+
61+
GPIO.output(Motor2A,GPIO.HIGH)
62+
GPIO.output(Motor2B,GPIO.LOW)
63+
GPIO.output(Motor2E,GPIO.HIGH)
64+
65+
sleep(2)
66+
67+
print "Going backwards"
68+
GPIO.output(Motor1A,GPIO.LOW)
69+
GPIO.output(Motor1B,GPIO.HIGH)
70+
GPIO.output(Motor1E,GPIO.HIGH)
71+
72+
GPIO.output(Motor2A,GPIO.LOW)
73+
GPIO.output(Motor2B,GPIO.HIGH)
74+
GPIO.output(Motor2E,GPIO.HIGH)
75+
76+
sleep(2)
77+
78+
print "Now stop"
79+
GPIO.output(Motor1E,GPIO.LOW)
80+
GPIO.output(Motor2E,GPIO.LOW)
81+
82+
GPIO.cleanup()

0 commit comments

Comments
 (0)