-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathglowpro2023_competition.py
252 lines (214 loc) · 5.7 KB
/
glowpro2023_competition.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
# SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
#
# SPDX-License-Identifier: MIT
from digitalio import DigitalInOut, Direction, Pull
import time
import board
import neopixel
'''
#############################################
######
###### INPUT MAP
######
###### Alliance: [pin7]
###### Alliance: 1 = blue, 0 = red
######
######
###### Input mapping for light display:
###### [pin13][pin12][pin11][pin10][pin9]
######
###### Input Number Mode
###### 11111 31 NO_CODE
###### 00001 1 DISABLED
###### 00010 2 CONE_MODE
###### 00011 3 CUBE_MODE
###### 00100 4 blinkingCone
###### 00101 5 blinkingCube
######
######
######
######
#############################################
#############################################
###### setup board output & neopixel light strip objects
#############################################
'''
pixel_pin = board.D5
num_pixels = 20
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False)
allianceColor=(0, 0, 0)
steps=30
wait=0.04
'''
#############################################
###### setup pins for input
#############################################
'''
#pin7
pin_alliance = DigitalInOut(board.D7)
pin_alliance.direction = Direction.INPUT
pin_alliance.pull = Pull.DOWN
#pin9
pin9 = DigitalInOut(board.D9)
pin9.direction = Direction.INPUT
pin9.pull = Pull.DOWN
#pin10
pin10 = DigitalInOut(board.D10)
pin10.direction = Direction.INPUT
pin10.pull = Pull.DOWN
#pin11
pin11 = DigitalInOut(board.D11)
pin11.direction = Direction.INPUT
pin11.pull = Pull.DOWN
#pin12
pin12 = DigitalInOut(board.D12)
pin12.direction = Direction.INPUT
pin12.pull = Pull.DOWN
#pin13
pin13 = DigitalInOut(board.D13)
pin13.direction = Direction.INPUT
pin13.pull = Pull.DOWN
'''
#############################################
###### color display functions
#############################################
'''
def enabled(isCone,current_mode):
if isCone:
color = (255, 165, 0)
else:
color = (145, 0, 255)
for i in range(15, 20, 1):
pixels[i]=color
for countdown in range(steps, 1, -1):
if read_current_mode() != current_mode:
return
for i in range(0, 15):
pixels[i]=(0, 255*countdown/steps, 0)
pixels.show()
time.sleep(wait)
for countup in range(1, steps, 1):
if read_current_mode() != current_mode:
return
for i in range(0, 15):
pixels[i]=(0, 255*countup/steps, 0)
pixels.show()
time.sleep(wait)
def no_code():
for noCode in range(20):
pixels[noCode]=(255, 0, 0)
pixels.show()
time.sleep(0.3)
for noCode in range(20):
pixels[noCode]=(0, 0, 0)
pixels.show()
time.sleep(0.3)
def disabled(current_mode):
for countdown in range(steps, 1, -1):
if read_current_mode() != current_mode:
return
for i in range(0, 20):
pixels[i]=(255*countdown/steps, 0, 0)
pixels.show()
time.sleep(wait)
for countup in range(1, steps, 1):
if read_current_mode() != current_mode:
return
for i in range(0, 20):
pixels[i]=(255*countup/steps, 0, 0)
pixels.show()
time.sleep(wait)
def blinkingCube():
for cube in range(15, 20, 1):
pixels[cube]=(255, 0, 0)
for cube in range(0, 15):
pixels[cube]=(145, 0, 255)
pixels.show()
time.sleep(0.3)
for cube in range(15):
pixels[cube]=(0, 0, 0)
pixels.show()
time.sleep(0.2)
def blinkingCone():
for cube in range(15, 20, 1):
pixels[cube]=(255, 0, 0)
for cone in range(0, 15):
pixels[cone]=(255, 165, 0)
pixels.show()
time.sleep(0.3)
for cone in range(15):
pixels[cone]=(0, 0, 0)
pixels.show()
time.sleep(0.2)
'''
#############################################
###### get current input from robot
#############################################
'''
def read_current_mode():
temp = int(pin9.value)
temp1 = int(pin10.value)<<1
temp2 = int(pin11.value)<<2
temp3 = int(pin12.value)<<3
temp4 = int(pin13.value)<<4
return (temp+temp1+temp2+temp3+temp4)
'''
#############################################
###### main loop
#############################################
'''
def main():
# Read mode and alliance from pins
mode = read_current_mode()
if pin_alliance.value == 1:
allianceColor = (0, 0, 255)
else:
allianceColor = (255, 0, 0)
#Select display option
if mode == 31:
no_code()
elif mode == 1:
disabled(mode)
elif mode == 2:
enabled(True,mode)
elif mode == 3:
enabled(False,mode)
elif mode == 4:
blinkingCone()
elif mode == 5:
blinkingCube()
else:
disabled(mode)
#time.sleep(0.01)
while True:
main()
####### EXTRAS ########
'''def lowBattery():
for lowBattery in range(20):
pixels[lowBattery]=(0, 255, 0)
pixels.show()
time.sleep(5/count)
for lowBattery in range(20):
pixels[lowBattery]=(240, 70, 0)
pixels.show()
time.sleep(1)
if count < 4:
for lowBattery in range(20):
pixels[lowBattery]=(0, 255, 0)
pixels.show()
time.sleep(5/count)
for lowBattery in range(20):
pixels[lowBattery]=(240, 70, 0)
pixels.show()
time.sleep(1)
elif count >= 4 and count >= 8:
for lowBattery in range(20):
pixels[lowBattery]=(240, 70, 0)
pixels.show()
time.sleep(5/(count-3))
for lowBattery in range(20):
pixels[lowBattery]=(255, 0, 0)
pixels.show()
time.sleep(1)
else:
pixels[lowBattery]=(255, 0, 0)'''