add circuitpy code

This commit is contained in:
Patrick Moessler 2023-06-05 01:55:11 +02:00
parent 6ad8e1c417
commit 8f1ad91e2b
2 changed files with 45 additions and 0 deletions

5
circuitpy/boot.py Normal file
View file

@ -0,0 +1,5 @@
import usb_cdc
import usb_midi
usb_cdc.enable(console=True, data=True)
usb_midi.disable()

40
circuitpy/code.py Normal file
View file

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