Here is my code to connect a keypad to my Raspberry Pi. Please help me to connect a 4 digit 7 segment using a keypad to my Raspberry Pi using Python.
from pad4pi import rpi_gpio
import time
# Setup Keypad
KEYPAD = [
["1","2","3","A"],
["4","5","6","B"],
["7","8","9","C"],
["*","0","#","D"]
]
# same as calling: factory.create_4_by_4_keypad, still we put here fyi:
ROW_PINS = [4, 14, 15, 17] # BCM numbering
COL_PINS = [18, 27, 22, 23] # BCM numbering
factory = rpi_gpio.KeypadFactory()
# Try factory.create_4_by_3_keypad
# and factory.create_4_by_4_keypad for reasonable defaults
keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS)
#keypad.cleanup()
def printKey(key):
print(key)
if (key=="1"):
print("number")
elif (key=="A"):
print("letter")
# printKey will be called each time a keypad button is pressed
keypad.registerKeyPressHandler(printKey)
try:
while(True):
time.sleep(0.2)
except:
keypad.cleanup()