Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keypad repetition removal #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions keypad.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,29 @@ def read_keypad(self):
return key_pressed
col_pin.value(1) # Set column pin back to HIGH
return None # Return None if no key is pressed





def key_read(keypad):
"""
Reads a single key press and waits for its release before returning.

Args:
keypad (Keypad): An instance of the Keypad class.

Returns:
str: The pressed key.
"""
value = None

while True:
key = keypad.read_keypad() # Read the keypad
if key: # A key is pressed
value = key # Store the pressed key
while keypad.read_keypad(): # Wait until the key is released
sleep(0.05) # Small delay to reduce CPU usage
break # Exit the loop once the key is released

return value # Return the detected key