Bit of a newbie so bear with:
I am trying to make a crude 60s timer that is reset and starts again on the rising edge of a trigger (ie when a gate goes high). The problem I have is that it won't reset and restart unless the timer has completed (ie reached zero). How do I interrupt the while loop and get it to start again?
Here is my code:
import keyboard
import time
t=60
last = False
current = False
while True:
current = keyboard.is_pressed('space') # triggered when space bar is pressed
if last == 0 and current == 1:
while t>=0:
print(t)
t-=1
time.sleep(1)
last = current # reset