forked from arim215/nhl_goal_light
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestDigits.py
executable file
·362 lines (307 loc) · 8.51 KB
/
TestDigits.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
import random
import os
import platform
import time
if "armv" in platform.machine() :
# import GPIO if running on RPI
import RPi.GPIO as GPIO
else :
# import gpio_mock if not running on RPI
from lib import gpio_mock as GPIO
HAWKS_A=38
HAWKS_B=36
HAWKS_C=32
HAWKS_D=22
HAWKS_E=18
HAWKS_F=16
HAWKS_G=7
OPPOSITION_A=37
OPPOSITION_B=33
OPPOSITION_C=31
OPPOSITION_D=29
OPPOSITION_E=15
OPPOSITION_F=13
OPPOSITION_G=11
def setup():
""" Function to setup raspberry pi GPIO mode and warnings. PIN 7 OUT and PIN 15 IN """
# Setup GPIO on raspberry pi
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(7, GPIO.OUT, initial=GPIO.LOW) # Tell the program you want to use pin number 7 as output. Relay is ACTIVE LOW, so OFF is HIGH
#GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set GPIO 15 as a PULL DOWN switch
#GPIO.add_event_detect(15, GPIO.RISING, activate_goal_light, 5000)
GPIO.setup(HAWKS_A, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(HAWKS_B, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(HAWKS_C, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(HAWKS_D, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(HAWKS_E, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(HAWKS_F, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(HAWKS_G, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(OPPOSITION_A, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(OPPOSITION_B, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(OPPOSITION_C, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(OPPOSITION_D, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(OPPOSITION_E, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(OPPOSITION_F, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(OPPOSITION_G, GPIO.OUT, initial=GPIO.LOW)
def writeScore(score):
if score == 0:
write0()
if score == 1:
write1()
if score == 2:
write2()
if score == 3:
write3()
if score == 4:
write4()
if score == 5:
write5()
if score == 6:
write6()
if score == 7:
write7()
if score == 8:
write8()
if score == 9:
write9()
def writeOppositionScore(score):
if score == 0:
write0_OPP()
if score == 1:
write1_OPP()
if score == 2:
write2_OPP()
if score == 3:
write3_OPP()
if score == 4:
write4_OPP()
if score == 5:
write5_OPP()
if score == 6:
write6_OPP()
if score == 7:
write7_OPP()
if score == 8:
write8_OPP()
if score == 9:
write9_OPP()
def shutdownScoreboard():
GPIO.output(HAWKS_A, GPIO.LOW)
GPIO.output(HAWKS_B, GPIO.LOW)
GPIO.output(HAWKS_C, GPIO.LOW)
GPIO.output(HAWKS_D, GPIO.LOW)
GPIO.output(HAWKS_E, GPIO.LOW)
GPIO.output(HAWKS_F, GPIO.LOW)
GPIO.output(HAWKS_G, GPIO.LOW)
GPIO.output(OPPOSITION_A, GPIO.LOW)
GPIO.output(OPPOSITION_B, GPIO.LOW)
GPIO.output(OPPOSITION_C, GPIO.LOW)
GPIO.output(OPPOSITION_D, GPIO.LOW)
GPIO.output(OPPOSITION_E, GPIO.LOW)
GPIO.output(OPPOSITION_F, GPIO.LOW)
GPIO.output(OPPOSITION_G, GPIO.LOW)
def write0():
GPIO.output(HAWKS_A, GPIO.HIGH)
GPIO.output(HAWKS_B, GPIO.HIGH)
GPIO.output(HAWKS_C, GPIO.HIGH)
GPIO.output(HAWKS_D, GPIO.HIGH)
GPIO.output(HAWKS_E, GPIO.HIGH)
GPIO.output(HAWKS_F, GPIO.HIGH)
GPIO.output(HAWKS_G, GPIO.LOW)
def write1():
GPIO.output(HAWKS_A, GPIO.LOW)
GPIO.output(HAWKS_B, GPIO.HIGH)
GPIO.output(HAWKS_C, GPIO.HIGH)
GPIO.output(HAWKS_D, GPIO.LOW)
GPIO.output(HAWKS_E, GPIO.LOW)
GPIO.output(HAWKS_F, GPIO.LOW)
GPIO.output(HAWKS_G, GPIO.LOW)
def write2():
GPIO.output(HAWKS_A, GPIO.HIGH)
GPIO.output(HAWKS_B, GPIO.HIGH)
GPIO.output(HAWKS_C, GPIO.LOW)
GPIO.output(HAWKS_D, GPIO.HIGH)
GPIO.output(HAWKS_E, GPIO.HIGH)
GPIO.output(HAWKS_F, GPIO.LOW)
GPIO.output(HAWKS_G, GPIO.HIGH)
def write3():
GPIO.output(HAWKS_A, GPIO.HIGH)
GPIO.output(HAWKS_B, GPIO.HIGH)
GPIO.output(HAWKS_C, GPIO.HIGH)
GPIO.output(HAWKS_D, GPIO.HIGH)
GPIO.output(HAWKS_E, GPIO.LOW)
GPIO.output(HAWKS_F, GPIO.LOW)
GPIO.output(HAWKS_G, GPIO.HIGH)
def write4():
GPIO.output(HAWKS_A, GPIO.LOW)
GPIO.output(HAWKS_B, GPIO.HIGH)
GPIO.output(HAWKS_C, GPIO.HIGH)
GPIO.output(HAWKS_D, GPIO.LOW)
GPIO.output(HAWKS_E, GPIO.LOW)
GPIO.output(HAWKS_F, GPIO.HIGH)
GPIO.output(HAWKS_G, GPIO.HIGH)
def write5():
GPIO.output(HAWKS_A, GPIO.HIGH)
GPIO.output(HAWKS_B, GPIO.LOW)
GPIO.output(HAWKS_C, GPIO.HIGH)
GPIO.output(HAWKS_D, GPIO.HIGH)
GPIO.output(HAWKS_E, GPIO.LOW)
GPIO.output(HAWKS_F, GPIO.HIGH)
GPIO.output(HAWKS_G, GPIO.HIGH)
def write6():
GPIO.output(HAWKS_A, GPIO.HIGH)
GPIO.output(HAWKS_B, GPIO.LOW)
GPIO.output(HAWKS_C, GPIO.HIGH)
GPIO.output(HAWKS_D, GPIO.HIGH)
GPIO.output(HAWKS_E, GPIO.HIGH)
GPIO.output(HAWKS_F, GPIO.HIGH)
GPIO.output(HAWKS_G, GPIO.HIGH)
def write7():
GPIO.output(HAWKS_A, GPIO.HIGH)
GPIO.output(HAWKS_B, GPIO.HIGH)
GPIO.output(HAWKS_C, GPIO.HIGH)
GPIO.output(HAWKS_D, GPIO.LOW)
GPIO.output(HAWKS_E, GPIO.LOW)
GPIO.output(HAWKS_F, GPIO.LOW)
GPIO.output(HAWKS_G, GPIO.LOW)
def write8():
GPIO.output(HAWKS_A, GPIO.HIGH)
GPIO.output(HAWKS_B, GPIO.HIGH)
GPIO.output(HAWKS_C, GPIO.HIGH)
GPIO.output(HAWKS_D, GPIO.HIGH)
GPIO.output(HAWKS_E, GPIO.HIGH)
GPIO.output(HAWKS_F, GPIO.HIGH)
GPIO.output(HAWKS_G, GPIO.HIGH)
def write9():
GPIO.output(HAWKS_A, GPIO.HIGH)
GPIO.output(HAWKS_B, GPIO.HIGH)
GPIO.output(HAWKS_C, GPIO.HIGH)
GPIO.output(HAWKS_D, GPIO.LOW)
GPIO.output(HAWKS_E, GPIO.LOW)
GPIO.output(HAWKS_F, GPIO.HIGH)
GPIO.output(HAWKS_G, GPIO.HIGH)
def write0_OPP():
GPIO.output(OPPOSITION_A, GPIO.HIGH)
GPIO.output(OPPOSITION_B, GPIO.HIGH)
GPIO.output(OPPOSITION_C, GPIO.HIGH)
GPIO.output(OPPOSITION_D, GPIO.HIGH)
GPIO.output(OPPOSITION_E, GPIO.HIGH)
GPIO.output(OPPOSITION_F, GPIO.HIGH)
GPIO.output(OPPOSITION_G, GPIO.LOW)
def write1_OPP():
GPIO.output(OPPOSITION_A, GPIO.LOW)
GPIO.output(OPPOSITION_B, GPIO.HIGH)
GPIO.output(OPPOSITION_C, GPIO.HIGH)
GPIO.output(OPPOSITION_D, GPIO.LOW)
GPIO.output(OPPOSITION_E, GPIO.LOW)
GPIO.output(OPPOSITION_F, GPIO.LOW)
GPIO.output(OPPOSITION_G, GPIO.LOW)
def write2_OPP():
GPIO.output(OPPOSITION_A, GPIO.HIGH)
GPIO.output(OPPOSITION_B, GPIO.HIGH)
GPIO.output(OPPOSITION_C, GPIO.LOW)
GPIO.output(OPPOSITION_D, GPIO.HIGH)
GPIO.output(OPPOSITION_E, GPIO.HIGH)
GPIO.output(OPPOSITION_F, GPIO.LOW)
GPIO.output(OPPOSITION_G, GPIO.HIGH)
def write3_OPP():
GPIO.output(OPPOSITION_A, GPIO.HIGH)
GPIO.output(OPPOSITION_B, GPIO.HIGH)
GPIO.output(OPPOSITION_C, GPIO.HIGH)
GPIO.output(OPPOSITION_D, GPIO.HIGH)
GPIO.output(OPPOSITION_E, GPIO.LOW)
GPIO.output(OPPOSITION_F, GPIO.LOW)
GPIO.output(OPPOSITION_G, GPIO.HIGH)
def write4_OPP():
GPIO.output(OPPOSITION_A, GPIO.LOW)
GPIO.output(OPPOSITION_B, GPIO.HIGH)
GPIO.output(OPPOSITION_C, GPIO.HIGH)
GPIO.output(OPPOSITION_D, GPIO.LOW)
GPIO.output(OPPOSITION_E, GPIO.LOW)
GPIO.output(OPPOSITION_F, GPIO.HIGH)
GPIO.output(OPPOSITION_G, GPIO.HIGH)
def write5_OPP():
GPIO.output(OPPOSITION_A, GPIO.HIGH)
GPIO.output(OPPOSITION_B, GPIO.LOW)
GPIO.output(OPPOSITION_C, GPIO.HIGH)
GPIO.output(OPPOSITION_D, GPIO.HIGH)
GPIO.output(OPPOSITION_E, GPIO.LOW)
GPIO.output(OPPOSITION_F, GPIO.HIGH)
GPIO.output(OPPOSITION_G, GPIO.HIGH)
def write6_OPP():
GPIO.output(OPPOSITION_A, GPIO.HIGH)
GPIO.output(OPPOSITION_B, GPIO.LOW)
GPIO.output(OPPOSITION_C, GPIO.HIGH)
GPIO.output(OPPOSITION_D, GPIO.HIGH)
GPIO.output(OPPOSITION_E, GPIO.HIGH)
GPIO.output(OPPOSITION_F, GPIO.HIGH)
GPIO.output(OPPOSITION_G, GPIO.HIGH)
def write7_OPP():
GPIO.output(OPPOSITION_A, GPIO.HIGH)
GPIO.output(OPPOSITION_B, GPIO.HIGH)
GPIO.output(OPPOSITION_C, GPIO.HIGH)
GPIO.output(OPPOSITION_D, GPIO.LOW)
GPIO.output(OPPOSITION_E, GPIO.LOW)
GPIO.output(OPPOSITION_F, GPIO.LOW)
GPIO.output(OPPOSITION_G, GPIO.LOW)
def write8_OPP():
GPIO.output(OPPOSITION_A, GPIO.HIGH)
GPIO.output(OPPOSITION_B, GPIO.HIGH)
GPIO.output(OPPOSITION_C, GPIO.HIGH)
GPIO.output(OPPOSITION_D, GPIO.HIGH)
GPIO.output(OPPOSITION_E, GPIO.HIGH)
GPIO.output(OPPOSITION_F, GPIO.HIGH)
GPIO.output(OPPOSITION_G, GPIO.HIGH)
def write9_OPP():
GPIO.output(OPPOSITION_A, GPIO.HIGH)
GPIO.output(OPPOSITION_B, GPIO.HIGH)
GPIO.output(OPPOSITION_C, GPIO.HIGH)
GPIO.output(OPPOSITION_D, GPIO.LOW)
GPIO.output(OPPOSITION_E, GPIO.LOW)
GPIO.output(OPPOSITION_F, GPIO.HIGH)
GPIO.output(OPPOSITION_G, GPIO.HIGH)
print("Testing Scoreboard Digits...")
setup()
print("0")
write0_OPP()
write0()
time.sleep(1)
print("1")
write1_OPP()
write1()
time.sleep(1)
print("2")
write2_OPP()
write2()
time.sleep(1)
print("3")
write3_OPP()
write3()
time.sleep(1)
print("4")
write4_OPP()
write4()
time.sleep(1)
print("5")
write5_OPP()
write5()
time.sleep(1)
print("6")
write6_OPP()
write6()
time.sleep(1)
print("7")
write7_OPP()
write7()
time.sleep(1)
print("8")
write8_OPP()
write8()
time.sleep(1)
print("9")
write9_OPP()
write9()
time.sleep(1)
print("Testing finished")
shutdownScoreboard()