-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt_functions.py
More file actions
53 lines (51 loc) · 1.37 KB
/
gpt_functions.py
File metadata and controls
53 lines (51 loc) · 1.37 KB
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
import RPi.GPIO as GPIO
import time
GPIO.cleanup()
GPIO.setmode(GPIO.BOARD)
motor_1_pins = 13, 15
motor_2_pins = 16, 18
ena = 38
enb = 40
for pin in motor_1_pins + motor_2_pins:
GPIO.setup(pin, GPIO.OUT)
def set_motor_a(direction):
if direction == 0:
GPIO.output(ena, False)
elif direction == 1:
GPIO.output(ena, True)
GPIO.output(motor_1_pins[0], False)
GPIO.output(motor_1_pins[1], True)
elif direction == 2:
GPIO.output(ena, True)
GPIO.output(motor_1_pins[1], False)
GPIO.output(motor_1_pins[0], True)
def set_motor_b(direction):
if direction == 0:
GPIO.output(enb, False)
elif direction == 1:
GPIO.output(enb, True)
GPIO.output(motor_2_pins[0], False)
GPIO.output(motor_2_pins[1], True)
elif direction == 2:
GPIO.output(enb, True)
GPIO.output(motor_2_pins[1], False)
GPIO.output(motor_2_pins[0], True)
def move(seconds, direction):
assert direction in (0, 1, 2, 3)
if direction == 0:
set_motor_a(1)
set_motor_b(1)
elif direction == 1:
set_motor_a(2)
set_motor_b(2)
elif direction == 2:
set_motor_a(2)
set_motor_b(1)
elif direction == 3:
set_motor_a(1)
set_motor_b(2)
time.sleep(seconds)
set_motor_a(0)
set_motor_b(0)
if __name__ == "__main__":
move(9, 1)