Created
April 28, 2020 14:05
-
-
Save ri0t/a5c90823e5b3c9e28ea22d1362a68513 to your computer and use it in GitHub Desktop.
Working with timeouts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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