Skip to content

Adding multikey example. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions examples/neokey_1x4_multikey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
# SPDX-License-Identifier: MIT
"""Example for connecting two NeoKey 1x4 breakouts. Requires bridging the A0 jumper on one board."""
import board
from adafruit_neokey.neokey1x4 import NeoKey1x4

try:
from _pixelbuf import colorwheel
except ImportError:
from adafruit_pypixelbuf import colorwheel

# Create a NeoKey object
neokey1 = NeoKey1x4(board.I2C())
neokey2 = NeoKey1x4(board.I2C(), addr=0x31)

keys = [
(neokey1, 0, colorwheel(0)),
(neokey1, 1, colorwheel(32)),
(neokey1, 2, colorwheel(64)),
(neokey1, 3, colorwheel(96)),
(neokey2, 0, colorwheel(128)),
(neokey2, 1, colorwheel(160)),
(neokey2, 2, colorwheel(192)),
(neokey2, 3, colorwheel(224)),
]

off = (0, 0, 0)

# Check each button, if pressed, light up the matching NeoPixel!
while True:
for i in range(8):
neokey, key_number, color = keys[i]
if neokey[key_number]:
print("Button", i)
neokey.pixels[key_number] = color
else:
neokey.pixels[key_number] = off