Skip to content

Instantly share code, notes, and snippets.

@ri0t
Created April 28, 2020 14:05
Show Gist options
  • Save ri0t/a5c90823e5b3c9e28ea22d1362a68513 to your computer and use it in GitHub Desktop.
Save ri0t/a5c90823e5b3c9e28ea22d1362a68513 to your computer and use it in GitHub Desktop.
Working with timeouts
# Assumption is that at this point, imports and keypad initialization have been done
timeout = 15 # Seconds, until entry is reset
entry_begin = 0 # Timestamp when entry began
sequence = "" # Entrysequence with keys appended
pin = "1234"
idle_time = 0.05 # 50 ms, should work fine
while True:
now = time.time()
entry = kp.getkey()
if entry is not None:
sequence += entry
entry = None
entry_begin = time.now()
if entry_begin + timeout >= now:
print("Timeout")
sequence = []
entry_begin = 0
if sequence == pin:
print("Yay")
# To idle loop:
time.sleep(idle_time)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment