# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT """NeoKey simpletest.""" import board from adafruit_neokey.neokey1x4 import NeoKey1x4 import busio # from digitalio import DigitalInOut, Direction, Pull from usb_cdc import data while True: try: i2c_bus = busio.I2C(scl=board.GP27, sda=board.GP26) # int_pin = DigitalInOut(board.GP28) # int_pin.direction = Direction.INPUT # int_pin.pull = Pull.UP neokey = NeoKey1x4(i2c_bus, addr=0x30) states=[False]*4 data.write('R0\n'.encode('utf-8')) data.write('R1\n'.encode('utf-8')) data.write('R2\n'.encode('utf-8')) data.write('R3\n'.encode('utf-8')) while True: for i in range(4): if neokey[i] != states[i]: states[i] = neokey[i] data.write(f'{"P" if states[i] else "R"}{i}\n'.encode('utf-8')) if data.in_waiting > 7: cmd = data.readline().decode() i=int(cmd[0]) color=int(cmd[1:7], 16) print(f'i:{i},c:{color}') neokey.pixels[i] = color except OSError as e : print(e)