-
Notifications
You must be signed in to change notification settings - Fork 0
/
Workshop_Script.py
84 lines (65 loc) · 1.64 KB
/
Workshop_Script.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
77
78
79
80
81
82
83
84
import time
import RPi.GPIO as GPIO
mode = GPIO.getmode()
GPIO.cleanup()
left_forward = 26
left_backward = 19
right_forward = 16
right_backward = 13
sleep_time = 1
FORWARD = 'forward'
BACKWARD = 'backward'
pwm_frequency = 200
GPIO.setmode(GPIO.BCM)
GPIO.setup(left_forward, GPIO.OUT)
GPIO.setup(left_backward, GPIO.OUT)
GPIO.setup(right_forward, GPIO.OUT)
GPIO.setup(right_backward, GPIO.OUT)
'''
#######
Skip to line 74 (runExperiment)
You don't need to edit this section, but you can with a more advance group
'''
def forward(x):
GPIO.output(left_forward, GPIO.HIGH)
GPIO.output(right_forward, GPIO.HIGH)
print("Moving Forward")
time.sleep(x)
GPIO.output(left_forward, GPIO.LOW)
GPIO.output(right_forward, GPIO.LOW)
def reverse(x):
GPIO.output(left_backward, GPIO.HIGH)
GPIO.output(right_backward, GPIO.HIGH)
print("Moving Backward")
time.sleep(x)
GPIO.output(left_backward, GPIO.LOW)
GPIO.output(right_backward, GPIO.LOW)
def leftWheel(direction, x):
pin = left_backward
if direction == FORWARD:
pin = left_forward
GPIO.output(pin, GPIO.HIGH)
print("left wheel " + direction)
time.sleep(x)
GPIO.output(pin, GPIO.LOW)
def rightWheel(direction, x):
pin = right_backward
if direction == FORWARD:
pin = right_forward
GPIO.output(pin, GPIO.HIGH)
print("Right wheel " + direction)
time.sleep(x)
GPIO.output(pin, GPIO.LOW)
'''
#######
This is the only thing you should need to change
'''
def runExperiment():
forward(1)
reverse(1)
leftWheel(FORWARD, 1)
rightWheel(BACKWARD, 5)
while 1:
runExperiment()
GPIO.cleanup()
break