Catch a case where the user submits 0:00 as set time, and actually give the user feedback when long-pressing the button before starting the timer

This commit is contained in:
David Thurstenson 2023-08-10 06:21:55 -05:00
parent 06df87ee19
commit adc3e61069
1 changed files with 11 additions and 4 deletions

View File

@ -60,6 +60,7 @@ text_area.y = 12
try:
display.show(text_area)
except:
print("Unable to print to display.")
pass
# END Display setup
@ -70,7 +71,7 @@ except:
# Neopixel setup
# Set Constants
pixel_pin = board.GP5
pixel_pin = board.GP10
num_pixels = 144
brightness = 0.1
@ -88,7 +89,7 @@ pixels = neopixel.NeoPixel(
RED = (255, 0, 0, 0)
YELLOW = (255, 150, 0, 0)
GREEN = (0, 255, 0, 0)
BLANK = (0, 0, 0, 0)
BLANK = (0, 0, 0)
# Turn all pixels off
pixels.fill(BLANK)
@ -223,7 +224,12 @@ def countdown(
# the total numbers of pixels, and rounded to the nearest
# decimal. This results in a number of pixels proportional
# to the elapsed time
current_position = round(num_pixels * ((seconds - current_time) / seconds))
try:
current_position = round(num_pixels * ((seconds - current_time) / seconds))
except ZeroDivisionError:
# If the previous line was deviding by zero, then just
# call for *all* pixels to be lit
current_position = num_pixels
# Catch a couple of special cases
if current_position == 0:
@ -303,7 +309,7 @@ while True:
set_time += set_time_step
# Counter-clockwise turn decreases set_time by set_time_step
# only until 0
elif set_time > 0:
elif set_time > 1:
set_time -= set_time_step
# Update the position tracker
last_position = position
@ -317,6 +323,7 @@ while True:
# (eventually, set_time_orig will be read from persistent config)
set_time = set_time_orig
# Give the user feedback
text_area.text = prettytime(set_time)
print("Time reset to: " + prettytime(set_time))
# Start the timer on single short press