Skip to content

Commit 03a35bb

Browse files
authored
Merge pull request #2 from kattni/multi-1x4-example
Adding multikey example.
2 parents 8e2d899 + 7c518a5 commit 03a35bb

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

examples/neokey_1x4_multikey.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
"""Example for connecting two NeoKey 1x4 breakouts. Requires bridging the A0 jumper on one board."""
4+
import board
5+
from adafruit_neokey.neokey1x4 import NeoKey1x4
6+
7+
try:
8+
from _pixelbuf import colorwheel
9+
except ImportError:
10+
from adafruit_pypixelbuf import colorwheel
11+
12+
# Create a NeoKey object
13+
neokey1 = NeoKey1x4(board.I2C())
14+
neokey2 = NeoKey1x4(board.I2C(), addr=0x31)
15+
16+
keys = [
17+
(neokey1, 0, colorwheel(0)),
18+
(neokey1, 1, colorwheel(32)),
19+
(neokey1, 2, colorwheel(64)),
20+
(neokey1, 3, colorwheel(96)),
21+
(neokey2, 0, colorwheel(128)),
22+
(neokey2, 1, colorwheel(160)),
23+
(neokey2, 2, colorwheel(192)),
24+
(neokey2, 3, colorwheel(224)),
25+
]
26+
27+
off = (0, 0, 0)
28+
29+
# Check each button, if pressed, light up the matching NeoPixel!
30+
while True:
31+
for i in range(8):
32+
neokey, key_number, color = keys[i]
33+
if neokey[key_number]:
34+
print("Button", i)
35+
neokey.pixels[key_number] = color
36+
else:
37+
neokey.pixels[key_number] = off

0 commit comments

Comments
 (0)