Skip to content

Using Matrix Keypad with I2C Port Expander #11

Description

@djairjr

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions