commit 6cd338de1a7250f74c210cba5e0df3c64bab96e0 Author: Brennen Bearnes Date: Fri Oct 26 16:11:45 2018 -0600 initial commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ffd4400 --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +all: upload + +upload: + cp -r ./*.py /media/brennen/CIRCUITPY/ + cp -r ./lib /media/brennen/CIRCUITPY/ + sync diff --git a/main.py b/main.py new file mode 100644 index 0000000..1e42ff6 --- /dev/null +++ b/main.py @@ -0,0 +1,68 @@ +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) +BOUNCE_SECS = 0.100 + +gc.collect() +print(gc.mem_free()) + +switch_ins = tuple(digitalio.DigitalInOut(pin) for pin in SWITCH_PINS) +for switch_in in switch_ins: + switch_in.switch_to_input(pull=digitalio.Pull.UP) + +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 + else: + 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): + trellis.sync() + if not switch_in.value: + # If switch is pressed, it's pulled low. Debounce by waiting for bounce time. + time.sleep(BOUNCE_SECS) + print('switch: ', switch) + print(gc.mem_free()) + kbd.send(Keycode.LEFT_GUI, Keycode.TAB) + + # Wait for switch to be released. + while not switch_in.value: + pass