You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.9 KiB

import time
import board
import digitalio
import gc
import busio
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.mouse import Mouse
from adafruit_neotrellis.neotrellis import NeoTrellis
#create the i2c object for the trellis
i2c_bus = busio.I2C(board.SCL, board.SDA)
#create the trellis
trellis = NeoTrellis(i2c_bus)
SWITCH_PINS = (board.D5, board.D6, board.D9, board.D10, board.D11, board.D12, board.A1)
switch_ins = tuple(digitalio.DigitalInOut(pin) for pin in SWITCH_PINS)
for switch_in in switch_ins:
kbd = Keyboard()
OFF = (1, 0, 0)
LIT = (40, 20, 0)
states = {}
def toggle(event):
#turn the LED on when a rising edge is detected
if event.edge == NeoTrellis.EDGE_RISING:
states[event.number] = not states[event.number]
for state, value in states.items():
if value:
trellis.pixels[state] = LIT
trellis.pixels[state] = OFF
for i in range(16):
states[i] = False
#activate rising edge events on all keys
trellis.activate_key(i, NeoTrellis.EDGE_RISING)
#activate falling edge events on all keys
trellis.activate_key(i, NeoTrellis.EDGE_FALLING)
#set all keys to trigger the blink callback
trellis.callbacks[i] = toggle
"""Start shortcut processing. Run forever."""
while True:
for switch, switch_in in enumerate(switch_ins):
if not switch_in.value:
# If switch is pressed, it's pulled low. Debounce by waiting for bounce time.
print('switch: ', switch)
kbd.send(Keycode.LEFT_GUI, Keycode.TAB)
# Wait for switch to be released.
while not switch_in.value: