Simple test
Ensure your device works with this simple test.
examples/mcp23017_scanner_simpletest.py
1# SPDX-FileCopyrightText: Copyright (c) 2022 Neradoc
2#
3# SPDX-License-Identifier: Unlicense
4
5import board
6from supervisor import ticks_ms
7from adafruit_mcp230xx.mcp23017 import MCP23017
8from mcp23017_scanner import McpMatrixScanner
9
10# MCP23017 port A pins for columns
11COLUMNS = [0, 1, 2, 3, 4]
12# MCP23017 port B pins for rows
13ROWS = [0, 1, 2, 3, 4, 5]
14
15mcp = MCP23017(board.I2C())
16scanner = McpMatrixScanner(mcp, ROWS, COLUMNS, irq=board.D5) # irq is optional
17
18while True:
19 t0 = ticks_ms()
20 scanner.update()
21 while event := scanner.events.get():
22 key = scanner.key_number_to_row_column(event.key_number)
23 if event.pressed:
24 print(f"Key pressed : {key}")
25 if event.released:
26 print(f"Key released: {key}")
27
28 # flood print the milliseconds passed:
29 # print(ticks_ms() - t0)