-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotor_control.py
48 lines (42 loc) · 1.34 KB
/
motor_control.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
right_motor_1=
right_motor_2=
left_motor_1=
left_motor_2=
def gpio_setup():
"""Sets the GPIO pins for the two motors"""
GPIO.setmode(GPIO.BCM)
GPIO.setup(right_motor_1, GPIO.OUT)
GPIO.setup(right_motor_2, GPIO.OUT)
GPIO.setup(left_motor_1, GPIO.OUT)
GPIO.setup(left_motor_2, GPIO.OUT)
def instructions(command):
if command=="LEFT":
"""Set mode to Left"""
GPIO.output(right_motor_1, True)
GPIO.output(right_motor_2, False)
GPIO.output(left_motor_1, False)
GPIO.output(left_motor_2, True)
if command=="RIGHT":
"""Set mode to Right"""
GPIO.output(right_motor_1, False)
GPIO.output(right_motor_2, True)
GPIO.output(left_motor_1, True)
GPIO.output(left_motor_2, False)
if command=="FORWARD":
"""Set mode to Forward"""
GPIO.output(right_motor_1, True)
GPIO.output(right_motor_2, False)
GPIO.output(left_motor_1, True)
GPIO.output(left_motor_2,False)
if command=="BACK":
"""Set mode to Backward"""
GPIO.output(right_motor_1, False)
GPIO.output(right_motor_2, True)
GPIO.output(left_motor_1, False)
GPIO.output(left_motor_2, True)
if command=="no command":
GPIO.output(right_motor_1, False)
GPIO.output(right_motor_2, False)
GPIO.output(left_motor_1, False)
GPIO.output(left_motor_2, False)