From dcd0246843a2da7bdd6dd6a195e7e55372f7620a Mon Sep 17 00:00:00 2001 From: David Thurstenson Date: Sat, 15 Oct 2022 07:10:32 -0500 Subject: [PATCH] Catch a couple special cases - Light the first pixel on timer start - Wait to light the last pixel until timer has truly elapsed --- colorbar-fastloop.py | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/colorbar-fastloop.py b/colorbar-fastloop.py index 2facb96..c71318a 100644 --- a/colorbar-fastloop.py +++ b/colorbar-fastloop.py @@ -111,18 +111,34 @@ def countdown( # Do update stuff - # Loop over every pixel ID that should be lit - # based on the elapsed time - for pixel in range(round(num_pixels * ((seconds - current_time) / seconds))): - # Set pixel color stuff - if current_time < 0: - pass - elif current_time <= redtime: - colorizer(pixel, colormode, red=True) - elif current_time <= yellowtime: - colorizer(pixel, colormode, yellow=True) - else: - colorizer(pixel, colormode) + # Calculate the current position + current_position = round(num_pixels * ((seconds - current_time) / seconds)) + + # Catch a couple of special cases + if current_position == 0: + # Light the first LED when the timer starts + # regardless of other factors + colorizer(0, colormode) + elif current_position == num_pixels and current_time > 0: + # If current_position calls for *all* + # pixels to be lit, and the timer + # hasn't expired yet, don't do anything. + # This should delay the last pixel from + # lighting until the timer has fully elapsed + pass + else: + # Loop over every pixel ID that should be lit + # based on the elapsed time + for pixel in range(current_position): + # Set pixel color stuff + if current_time < 0: + pass + elif current_time <= redtime: + colorizer(pixel, colormode, red=True) + elif current_time <= yellowtime: + colorizer(pixel, colormode, yellow=True) + else: + colorizer(pixel, colormode) # Display the result IRL pixels.show()