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
 5import digitalio
 6import board
 7import adafruit_matrixkeypad
 8
 9# Membrane 3x4 matrix keypad - https://www.adafruit.com/product/419
10cols = [digitalio.DigitalInOut(x) for x in (board.D9, board.D6, board.D5)]
11rows = [digitalio.DigitalInOut(x) for x in (board.D13, board.D12, board.D11, board.D10)]
12
13# 3x4 matrix keypad - Rows and columns are mixed up for https://www.adafruit.com/product/3845
14# Use the same wiring as in the guide with the following setup lines:
15# cols = [digitalio.DigitalInOut(x) for x in (board.D11, board.D13, board.D9)]
16# rows = [digitalio.DigitalInOut(x) for x in (board.D12, board.D5, board.D6, board.D10)]
17
18keys = ((1, 2, 3), (4, 5, 6), (7, 8, 9), ("*", 0, "#"))
19
20keypad = adafruit_matrixkeypad.Matrix_Keypad(rows, cols, keys)
21
22while True:
23    keys = keypad.pressed_keys
24    if keys:
25        print("Pressed: ", keys)
26    time.sleep(0.1)