-
Notifications
You must be signed in to change notification settings - Fork 0
/
sx1509key.py
31 lines (27 loc) · 893 Bytes
/
sx1509key.py
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
import board
import busio
import adafruit_sx1509
import digitalio
class SX1509_Keypad:
def __init__(self, rows, cols):
i2c = busio.I2C(board.SCL, board.SDA)
self.sx1509 = adafruit_sx1509.SX1509(i2c)
self.rows = rows
self.cols = cols
self.keys = [
['1', '2', '3', 'A'],
['4', '5', '6', 'B'],
['7', '8', '9', 'C'],
['*', '0', '#', 'D']
]
self.key_down = None
# Set rows as input with pull-up
for r in self.rows:
self.sx1509.pin_mode(r, adafruit_sx1509.INPUT_PULLUP)
# Set cols as output
for c in self.cols:
self.sx1509.pin_mode(c, adafruit_sx1509.OUTPUT)
# Attach interrupt to rows
for r in self.rows:
self.sx1509.enable_interrupt(r, adafruit_sx1509.RISING)
self