Skip to content

Instantly share code, notes, and snippets.

@kentros
Created February 21, 2018 02:35
Show Gist options
  • Save kentros/ab5dd1b121ce40f1f3a6bc6069a81274 to your computer and use it in GitHub Desktop.
Save kentros/ab5dd1b121ce40f1f3a6bc6069a81274 to your computer and use it in GitHub Desktop.
how-to-use-a-4x4-keypad-in-python
# stolen from https://raspberrypi.stackexchange.com/questions/53665/how-to-use-a-4x4-keypad-in-python
from pad4pi import rpi_gpio
# Setup Keypad
KEYPAD = [
["1","2","3","A"],
["4","5","6","B"],
["7","8","9","C"],
["*","0","#","D"]
]
COL_PINS = [0,5,6,13] # BCM numbering
ROW_PINS = [19,26,20,21] # BCM numbering
factory = rpi_gpio.KeypadFactory()
keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS)
keypad.registerKeyPressHandler(processKey)
def processKey(key):
if (key=="1"):
print("number")
elif (key=="A"):
print("letter")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment