|
| 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