From 8f1ad91e2b0fa4066abec699f253dad95975f075 Mon Sep 17 00:00:00 2001 From: Patrick Moessler Date: Mon, 5 Jun 2023 01:55:11 +0200 Subject: [PATCH] add circuitpy code --- circuitpy/boot.py | 5 +++++ circuitpy/code.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 circuitpy/boot.py create mode 100644 circuitpy/code.py diff --git a/circuitpy/boot.py b/circuitpy/boot.py new file mode 100644 index 0000000..7c58d8f --- /dev/null +++ b/circuitpy/boot.py @@ -0,0 +1,5 @@ +import usb_cdc +import usb_midi + +usb_cdc.enable(console=True, data=True) +usb_midi.disable() diff --git a/circuitpy/code.py b/circuitpy/code.py new file mode 100644 index 0000000..e3e0276 --- /dev/null +++ b/circuitpy/code.py @@ -0,0 +1,40 @@ +# 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)