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

Using Matrix Keypad with I2C Port Expander #11

Open
djairjr opened this issue Feb 3, 2023 · 0 comments
Open

Using Matrix Keypad with I2C Port Expander #11

djairjr opened this issue Feb 3, 2023 · 0 comments

Comments

@djairjr
Copy link

djairjr commented Feb 3, 2023

Matrix Keypad

Using I2C Port Expander With Matrix Keypad

import adafruit_matrixkeypad
import adafruit_pcf8574
from digitalio import DigitalInOut
import board
import time
# Using default i2c with board.SDA e board.SCL
i2c = board.I2C()
pcf = adafruit_pcf8574.PCF8574(i2c, 0x20)

# Classic 3x4 matrix keypad
# I directly soldered the pcf8574 module on the keypad
# with pinout C2 R1 C1 R4 C3 R3 R2
cols = [pcf.get_pin(4), pcf.get_pin(6), pcf.get_pin(2)]
rows = [pcf.get_pin(5), pcf.get_pin(0), pcf.get_pin(1), pcf.get_pin(3)]

keys = ((1, 2, 3),
        (4, 5, 6),
        (7, 8, 9),
        ('*', 0, '#'))

keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)

while True:
    keys = keypad.pressed_keys
    if keys:
        print("Pressed: ", keys)
    time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant