-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpwm_motor.py
48 lines (43 loc) · 935 Bytes
/
pwm_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
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
M1_F = 17
M1_B = 18
M2_F = 22
M2_B = 23
GPIO.setup(M1_F, GPIO.OUT)
GPIO.setup(M1_B, GPIO.OUT)
GPIO.setup(M2_F, GPIO.OUT)
GPIO.setup(M2_B, GPIO.OUT)
m1f = GPIO.PWM(M1_F, 200)
m1b = GPIO.PWM(M1_B, 200)
m2f = GPIO.PWM(M2_F, 200)
m2b = GPIO.PWM(M2_B, 200)
try:
while True:
print "Forward 50%"
m1f.start(50)
m2f.start(50)
sleep(2)
print "Forward 100%"
m1f.ChangeDutyCycle(100)
m2f.ChangeDutyCycle(100)
sleep(2)
print "Stop"
m1f.stop()
m2f.stop()
sleep(1)
print "Backward 50%"
m1b.start(50)
m2b.start(50)
sleep(2)
print "Backwards 100%"
m1b.ChangeDutyCycle(100)
m2b.ChangeDutyCycle(100)
sleep(2)
print "M1 Stop"
m1b.stop()
m2b.stop()
sleep(1)
except:
GPIO.cleanup()