Skip to content

Commit 9401869

Browse files
authored
Merge pull request adafruit#8 from adafruit/3x4_oled
Adding 3x4 example with no OLED
2 parents 0d4ed59 + ca3bc1d commit 9401869

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

examples/tca8418_3x4_noOLED.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
5+
import time
6+
import board
7+
from adafruit_tca8418 import TCA8418
8+
9+
i2c = board.I2C() # uses board.SCL and board.SDA
10+
tca = TCA8418(i2c)
11+
12+
keymap = (("*", "0", "#"), ("7", "8", "9"), ("4", "5", "6"), ("1", "2", "3"))
13+
14+
# set up all R0-R2 pins and C0-C3 pins as keypads
15+
KEYPADPINS = (
16+
TCA8418.R0,
17+
TCA8418.R1,
18+
TCA8418.R2,
19+
TCA8418.C0,
20+
TCA8418.C1,
21+
TCA8418.C2,
22+
TCA8418.C3,
23+
)
24+
25+
# make them inputs with pullups
26+
for pin in KEYPADPINS:
27+
tca.keypad_mode[pin] = True
28+
# make sure the key pins generate FIFO events
29+
tca.enable_int[pin] = True
30+
# we will stick events into the FIFO queue
31+
tca.event_mode_fifo[pin] = True
32+
33+
# turn on INT output pin
34+
tca.key_intenable = True
35+
36+
while True:
37+
if tca.key_int:
38+
# first figure out how big the queue is
39+
events = tca.events_count
40+
# now print keyevent, row, column & key name
41+
for _ in range(events):
42+
keyevent = tca.next_event
43+
# strip keyevent
44+
event = keyevent & 0x7F
45+
event -= 1
46+
# figure out row
47+
row = event // 10
48+
# figure out column
49+
col = event % 10
50+
# print event type first
51+
if keyevent & 0x80:
52+
print("Key down")
53+
else:
54+
print("Key up")
55+
# use row & column coordinates to print key name
56+
print("Row %d, Column %d, Key %s" % (row, col, keymap[col][row]))
57+
tca.key_int = True # clear the IRQ by writing 1 to it
58+
time.sleep(0.01)

0 commit comments

Comments
 (0)