@@ -112,10 +112,10 @@ def power(sound, duration, reverse):
112112 elapsed = time .monotonic () - start_time # Time spent playing sound
113113 if elapsed > duration : # Past sound duration?
114114 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
116116 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 )
119119 num = threshold - prev # Number of pixels to light on this pass
120120 if num != 0 :
121121 if reverse :
@@ -183,8 +183,10 @@ def mix(color_1, color_2, weight_2):
183183 # Setup for idle pulse
184184 idle_brightness = IDLE_PULSE_BRIGHTNESS_MIN
185185 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
188190 strip .show ()
189191
190192 elif mode >= 1 : # If not OFF mode...
@@ -204,7 +206,7 @@ def mix(color_1, color_2, weight_2):
204206 # make a larson scanner
205207 strip_backup = strip [0 :- 1 ]
206208 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
208210 if 0 <= i < len (strip ):
209211 strip [i ] = COLOR_SWING
210212 strip .show ()
@@ -218,21 +220,22 @@ def mix(color_1, color_2, weight_2):
218220 elif mode == 1 and accel_yell > YELL_THRESHOLD : # Motion on Y axis = YELL
219221 TRIGGER_TIME = time .monotonic () # Save initial time of swing
220222 # 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
223225 play_wav (random .choice (yell_sounds )) # Randomly choose from available yell sounds
224- duration = YELL_SOUND_DURATION
226+ sound_duration = YELL_SOUND_DURATION
225227 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?
228230 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
234237 strip .show ()
235- prev = threshold
238+ previous = pixel_threshold
236239 while audio .playing :
237240 pass # wait till we're done
238241 mode = 4 # we'll go back to idle mode
@@ -242,8 +245,11 @@ def mix(color_1, color_2, weight_2):
242245 if idle_brightness > IDLE_PULSE_BRIGHTNESS_MAX or \
243246 idle_brightness < IDLE_PULSE_BRIGHTNESS_MIN : # Then...
244247 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
247253 strip .show ()
248254 time .sleep (IDLE_PULSE_SPEED ) # Idle pulse speed set above
249255 elif mode > 1 : # If in SWING or HIT or YELL mode...
@@ -255,4 +261,4 @@ def mix(color_1, color_2, weight_2):
255261 strip .show ()
256262 else : # No sound now, but still SWING or HIT modes
257263 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