Simple test
Ensure your device works with this simple test.
examples/matrixkeypad_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5
6import board
7import digitalio
8
9import adafruit_matrixkeypad
10
11# Membrane 3x4 matrix keypad - https://www.adafruit.com/product/419
12cols = [digitalio.DigitalInOut(x) for x in (board.D9, board.D6, board.D5)]
13rows = [digitalio.DigitalInOut(x) for x in (board.D13, board.D12, board.D11, board.D10)]
14
15# 3x4 matrix keypad - Rows and columns are mixed up for https://www.adafruit.com/product/3845
16# Use the same wiring as in the guide with the following setup lines:
17# cols = [digitalio.DigitalInOut(x) for x in (board.D11, board.D13, board.D9)]
18# rows = [digitalio.DigitalInOut(x) for x in (board.D12, board.D5, board.D6, board.D10)]
19
20keys = ((1, 2, 3), (4, 5, 6), (7, 8, 9), ("*", 0, "#"))
21
22keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)
23
24while True:
25 keys = keypad.pressed_keys
26 if keys:
27 print("Pressed: ", keys)
28 time.sleep(0.1)