@@ -112,10 +112,10 @@ def power(sound, duration, reverse):
112
112
elapsed = time .monotonic () - start_time # Time spent playing sound
113
113
if elapsed > duration : # Past sound duration?
114
114
break # Stop animating
115
- animation_time = elapsed / duration # Animation time, 0.0 to 1.0
115
+ total_animation_time = elapsed / duration # Animation time, 0.0 to 1.0
116
116
if reverse :
117
- animation_time = 1.0 - animation_time # 1.0 to 0.0 if reverse
118
- threshold = int (NUM_PIXELS * animation_time + 0.5 )
117
+ total_animation_time = 1.0 - total_animation_time # 1.0 to 0.0 if reverse
118
+ threshold = int (NUM_PIXELS * total_animation_time + 0.5 )
119
119
num = threshold - prev # Number of pixels to light on this pass
120
120
if num != 0 :
121
121
if reverse :
@@ -183,8 +183,10 @@ def mix(color_1, color_2, weight_2):
183
183
# Setup for idle pulse
184
184
idle_brightness = IDLE_PULSE_BRIGHTNESS_MIN
185
185
idle_increment = 0.01
186
- strip [0 :NUM_RING ] = [([int (c * idle_brightness ) for c in COLOR_TOP ])] * NUM_RING #lights the ring in COLOR_TOP color
187
- strip [NUM_RING :NUM_PIXELS ] = [([int (c * idle_brightness ) for c in COLOR_IDLE ])] * NUM_STRIP #lights the strip in COLOR_IDLE color
186
+ # lights the ring in COLOR_TOP color:
187
+ strip [0 :NUM_RING ] = [([int (c * idle_brightness ) for c in COLOR_TOP ])] * NUM_RING
188
+ # lights the strip in COLOR_IDLE color:
189
+ strip [NUM_RING :NUM_PIXELS ] = [([int (c * idle_brightness ) for c in COLOR_IDLE ])] * NUM_STRIP
188
190
strip .show ()
189
191
190
192
elif mode >= 1 : # If not OFF mode...
@@ -204,7 +206,7 @@ def mix(color_1, color_2, weight_2):
204
206
# make a larson scanner
205
207
strip_backup = strip [0 :- 1 ]
206
208
for p in range (- 1 , len (strip )):
207
- for i in range (p - 1 , p + 2 ): # shoot a 'ray' of 3 pixels
209
+ for i in range (p - 1 , p + 2 ): # shoot a 'ray' of 3 pixels
208
210
if 0 <= i < len (strip ):
209
211
strip [i ] = COLOR_SWING
210
212
strip .show ()
@@ -218,21 +220,22 @@ def mix(color_1, color_2, weight_2):
218
220
elif mode == 1 and accel_yell > YELL_THRESHOLD : # Motion on Y axis = YELL
219
221
TRIGGER_TIME = time .monotonic () # Save initial time of swing
220
222
# run a color down the staff, opposite of power-up
221
- prev = 0
222
- start_time = time .monotonic () # Save audio start time
223
+ previous = 0
224
+ audio_start_time = time .monotonic () # Save audio start time
223
225
play_wav (random .choice (yell_sounds )) # Randomly choose from available yell sounds
224
- duration = YELL_SOUND_DURATION
226
+ sound_duration = YELL_SOUND_DURATION
225
227
while True :
226
- elapsed = time .monotonic () - start_time # Time spent playing sound
227
- if elapsed > duration : # Past sound duration?
228
+ time_elapsed = time .monotonic () - audio_start_time # Time spent playing sound
229
+ if time_elapsed > sound_duration : # Past sound duration?
228
230
break # Stop animating
229
- animation_time = elapsed / duration # Animation time, 0.0 to 1.0
230
- threshold = int (NUM_PIXELS * animation_time + 0.5 )
231
- num = threshold - prev # Number of pixels to light on this pass
232
- if num != 0 :
233
- strip [prev :threshold ] = [YELL_COLOR ] * num # light pixels in YELL_COLOR
231
+ animation_time = time_elapsed / sound_duration # Animation time, 0.0 to 1.0
232
+ pixel_threshold = int (NUM_PIXELS * animation_time + 0.5 )
233
+ num_pixels = pixel_threshold - previous # Number of pixels to light on this pass
234
+ if num_pixels != 0 :
235
+ # light pixels in YELL_COLOR:
236
+ strip [previous :pixel_threshold ] = [YELL_COLOR ] * num_pixels
234
237
strip .show ()
235
- prev = threshold
238
+ previous = pixel_threshold
236
239
while audio .playing :
237
240
pass # wait till we're done
238
241
mode = 4 # we'll go back to idle mode
@@ -242,8 +245,11 @@ def mix(color_1, color_2, weight_2):
242
245
if idle_brightness > IDLE_PULSE_BRIGHTNESS_MAX or \
243
246
idle_brightness < IDLE_PULSE_BRIGHTNESS_MIN : # Then...
244
247
idle_increment *= - 1 # Pulse direction flip
245
- strip [0 :NUM_RING ] = [([int (c * idle_brightness ) for c in COLOR_TOP ])] * NUM_RING #light the ring
246
- strip [NUM_RING :NUM_PIXELS ] = [([int (c * idle_brightness ) for c in COLOR_IDLE ])] * NUM_STRIP #light the strip
248
+ # light the ring:
249
+ strip [0 :NUM_RING ] = [([int (c * idle_brightness ) for c in COLOR_TOP ])] * NUM_RING
250
+ # light the strip:
251
+ strip [NUM_RING :NUM_PIXELS ] = [([int (c * idle_brightness ) for c in
252
+ COLOR_IDLE ])] * NUM_STRIP
247
253
strip .show ()
248
254
time .sleep (IDLE_PULSE_SPEED ) # Idle pulse speed set above
249
255
elif mode > 1 : # If in SWING or HIT or YELL mode...
@@ -255,4 +261,4 @@ def mix(color_1, color_2, weight_2):
255
261
strip .show ()
256
262
else : # No sound now, but still SWING or HIT modes
257
263
play_wav ('idle' , loop = True ) # Resume idle sound
258
- mode = 1 # Return to idle mode
264
+ mode = 1 # Return to idle mode
0 commit comments