-
Notifications
You must be signed in to change notification settings - Fork 1
/
3LED_test.py
159 lines (121 loc) · 2.69 KB
/
3LED_test.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#DragonBoard Code
# gpio example in python using mraa
#
# Author: Manivannan Sadhasivam <[email protected]>
# Modified by: Team 3 UCSD HARD Hacks 2018
# Usage: Toggles GPIO 23 and 24
#
# Execution: sudo python mraa_gpio.py
import mraa
import time
#========================SET-UP=========================
#ON/OFF for Left and Right
rl_bool = 0 #initially starts with 0 value for OFF
ll_bool = 0 #initially starts with 0 value for OFF
ul_bool = 0 #initially starts with 0 value for OFF
nothing_bool = 0 #initially starts with 0 value for OFF
#Left LED Block
L1_led = mraa.Gpio(23)
L2_led = mraa.Gpio(24)
L3_led = mraa.Gpio(25)
#Right LED Block
R1_led = mraa.Gpio(26)
R2_led = mraa.Gpio(27)
R3_led = mraa.Gpio(29)
#U-turn LEd Block
U1_led = mraa.Gpio(30)
U2_led = mraa.Gpio(31)
U3_led = mraa.Gpio(32)
# set LEFt LED to output
L1_led.dir(mraa.DIR_OUT)
L2_led.dir(mraa.DIR_OUT)
L3_led.dir(mraa.DIR_OUT)
# set right_led to output
R1_led.dir(mraa.DIR_OUT)
R2_led.dir(mraa.DIR_OUT)
R3_led.dir(mraa.DIR_OUT)
# set u_led to output
U1_led.dir(mraa.DIR_OUT)
U2_led.dir(mraa.DIR_OUT)
U3_led.dir(mraa.DIR_OUT)
"""
nothing: 0
left: 1
right: 2
u-turn: 3
"""
def light_up(dir_num):
if dir_num == 0: #do nothing
all_off()
elif dir_num == 1:
L1_led.write(1)
elif dir_num == 2:
L2_led.write(1)
elif dir_num == 3:
L3_led.write(1)
elif dir_num == 4:
R1_led.write(1)
elif dir_num == 5:
R2_led.write(1)
elif dir_num == 6:
R3_led.write(1)
elif dir_num == 7:
U1_led.write(1)
elif dir_num == 8:
U2_led.write(1)
elif dir_num == 9:
U3led.write(1)
elif dir_num == 10:
L1_led.write(1)
U1_led.write(1)
elif dir_num == 11:
L2_led.write(1)
U2_led.write(1)
elif dir_num == 12:
L3_led.write(1)
U3_led.write(1)
def all_off():
"""Turns off all the leds"""
L1_led.write(0)
L2_led.write(0)
L3_led.write(0)
R1_led.write(0)
R2_led.write(0)
R3_led.write(0)
U1_led.write(0)
U2_led.write(0)
U3_led.write(0)
if __name__ == "__main__":
#=========TESTING==========
time.sleep(2)
for i in range (3):
#Turn Left Sequence
light_up(1)
time.sleep(2)
light_up(2)
time.sleep(2)
light_up(3)
time.sleep(2)
#Reset Lights
light_up(0)
time.sleep(3)
#Turn Right Sequence
light_up(4)
time.sleep(2)
light_up(5)
time.sleep(2)
light_up(6)
time.sleep(2)
#Reset Lights
light_up(0)
time.sleep(3)
#U-Turn Sequence
light_up(4)
time.sleep(2)
light_up(5)
time.sleep(2)
light_up(6)
time.sleep(2)
#Reset Lights
light_up(0)
time.sleep(3)