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:
parent
06df87ee19
commit
adc3e61069
|
@ -60,6 +60,7 @@ text_area.y = 12
|
||||||
try:
|
try:
|
||||||
display.show(text_area)
|
display.show(text_area)
|
||||||
except:
|
except:
|
||||||
|
print("Unable to print to display.")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# END Display setup
|
# END Display setup
|
||||||
|
@ -70,7 +71,7 @@ except:
|
||||||
# Neopixel setup
|
# Neopixel setup
|
||||||
|
|
||||||
# Set Constants
|
# Set Constants
|
||||||
pixel_pin = board.GP5
|
pixel_pin = board.GP10
|
||||||
num_pixels = 144
|
num_pixels = 144
|
||||||
brightness = 0.1
|
brightness = 0.1
|
||||||
|
|
||||||
|
@ -88,7 +89,7 @@ pixels = neopixel.NeoPixel(
|
||||||
RED = (255, 0, 0, 0)
|
RED = (255, 0, 0, 0)
|
||||||
YELLOW = (255, 150, 0, 0)
|
YELLOW = (255, 150, 0, 0)
|
||||||
GREEN = (0, 255, 0, 0)
|
GREEN = (0, 255, 0, 0)
|
||||||
BLANK = (0, 0, 0, 0)
|
BLANK = (0, 0, 0)
|
||||||
|
|
||||||
# Turn all pixels off
|
# Turn all pixels off
|
||||||
pixels.fill(BLANK)
|
pixels.fill(BLANK)
|
||||||
|
@ -223,7 +224,12 @@ def countdown(
|
||||||
# the total numbers of pixels, and rounded to the nearest
|
# the total numbers of pixels, and rounded to the nearest
|
||||||
# decimal. This results in a number of pixels proportional
|
# decimal. This results in a number of pixels proportional
|
||||||
# to the elapsed time
|
# 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
|
# Catch a couple of special cases
|
||||||
if current_position == 0:
|
if current_position == 0:
|
||||||
|
@ -303,7 +309,7 @@ while True:
|
||||||
set_time += set_time_step
|
set_time += set_time_step
|
||||||
# Counter-clockwise turn decreases set_time by set_time_step
|
# Counter-clockwise turn decreases set_time by set_time_step
|
||||||
# only until 0
|
# only until 0
|
||||||
elif set_time > 0:
|
elif set_time > 1:
|
||||||
set_time -= set_time_step
|
set_time -= set_time_step
|
||||||
# Update the position tracker
|
# Update the position tracker
|
||||||
last_position = position
|
last_position = position
|
||||||
|
@ -317,6 +323,7 @@ while True:
|
||||||
# (eventually, set_time_orig will be read from persistent config)
|
# (eventually, set_time_orig will be read from persistent config)
|
||||||
set_time = set_time_orig
|
set_time = set_time_orig
|
||||||
# Give the user feedback
|
# Give the user feedback
|
||||||
|
text_area.text = prettytime(set_time)
|
||||||
print("Time reset to: " + prettytime(set_time))
|
print("Time reset to: " + prettytime(set_time))
|
||||||
|
|
||||||
# Start the timer on single short press
|
# Start the timer on single short press
|
||||||
|
|
Loading…
Reference in New Issue