-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeypad_code.py
More file actions
37 lines (28 loc) · 945 Bytes
/
keypad_code.py
File metadata and controls
37 lines (28 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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; Board numbering is: 7,8,10,11 (see pinout.xyz/)
COL_PINS = [18, 27, 22, 23] # BCM numbering; Board numbering is: 12,13,15,16 (see pinout.xyz/)
factory = rpi_gpio.KeypadFactory()
# Try keypad = factory.create_4_by_3_keypad() or
# Try keypad = factory.create_4_by_4_keypad() #for reasonable defaults
# or define your own:
keypad = factory.create_keypad(keypad=KEYPAD, row_pins=ROW_PINS, col_pins=COL_PINS)
#keypad.cleanup()
def printKey(key):
print(key)
# printKey will be called each time a keypad button is pressed
keypad.registerKeyPressHandler(printKey)
try:
while(True):
time.sleep(0.2)
except:
keypad.cleanup()
#keypad.cleanup()