-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot.py
76 lines (58 loc) · 1.39 KB
/
robot.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
import RPi.GPIO as GPIO
from time import sleep
pwm_A = 0
pwm_B = 0
# Pins for Motor Driver Inputs
Motor1A = 14
Motor1B = 15
Motor1E = 18
Motor2A = 5
Motor2B = 6
Motor2E = 13
def motorStop():#Motor stops
GPIO.output(Motor1A, GPIO.LOW)
GPIO.output(Motor1B, GPIO.LOW)
GPIO.output(Motor2A, GPIO.LOW)
GPIO.output(Motor2B, GPIO.LOW)
GPIO.output(Motor1E, GPIO.LOW)
GPIO.output(Motor2E, GPIO.LOW)
def Motor():
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor2A,GPIO.HIGH)
GPIO.output(Motor2B,GPIO.LOW)
pwm_B.start(100)
pwm_B.ChangeDutyCycle(speed)
def setup():
global pwm_a, pwm_b
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
GPIO.setup(Motor2A,GPIO.OUT)
GPIO.setup(Motor2B,GPIO.OUT)
GPIO.setup(Motor2E,GPIO.OUT)
try:
pwm_A = GPIO.PWM(Motor1E, 1000)
pwm_B = GPIO.PWM(Motor1E, 1000)
except:
pass
def loop():
# Going forwards
Motor()
print("Going forwards")
sleep(5)
# Going backwards
print("Going backwards")
sleep(5)
# Stop
print("Stop")
def destroy():
GPIO.cleanup()
if __name__ == '__main__':
setup()
try:
loop()
except KeyboardInterrupt:
destroy()