Browse Source

initial commit

Brennen Bearnes 10 months ago
commit
6cd338de1a
2 changed files with 74 additions and 0 deletions
  1. 6
    0
      Makefile
  2. 68
    0
      main.py

+ 6
- 0
Makefile View File

@@ -0,0 +1,6 @@
1
+all: upload
2
+
3
+upload:
4
+	cp -r ./*.py /media/brennen/CIRCUITPY/
5
+	cp -r ./lib /media/brennen/CIRCUITPY/
6
+	sync

+ 68
- 0
main.py View File

@@ -0,0 +1,68 @@
1
+import time
2
+import board
3
+import digitalio
4
+import gc
5
+import busio
6
+
7
+from adafruit_hid.keyboard import Keyboard
8
+from adafruit_hid.keycode import Keycode
9
+from adafruit_hid.mouse import Mouse
10
+from adafruit_neotrellis.neotrellis import NeoTrellis
11
+
12
+#create the i2c object for the trellis
13
+i2c_bus = busio.I2C(board.SCL, board.SDA)
14
+
15
+#create the trellis
16
+trellis = NeoTrellis(i2c_bus)
17
+
18
+SWITCH_PINS = (board.D5, board.D6, board.D9, board.D10, board.D11, board.D12, board.A1)
19
+BOUNCE_SECS = 0.100
20
+
21
+gc.collect()
22
+print(gc.mem_free())
23
+
24
+switch_ins = tuple(digitalio.DigitalInOut(pin) for pin in SWITCH_PINS)
25
+for switch_in in switch_ins:
26
+    switch_in.switch_to_input(pull=digitalio.Pull.UP)
27
+
28
+kbd = Keyboard()
29
+
30
+OFF = (1, 0, 0)
31
+LIT = (40, 20, 0)
32
+
33
+states = {}
34
+
35
+def toggle(event):
36
+    #turn the LED on when a rising edge is detected
37
+    if event.edge == NeoTrellis.EDGE_RISING:
38
+        states[event.number] = not states[event.number]
39
+
40
+        for state, value in states.items():
41
+            if value:
42
+                trellis.pixels[state] = LIT
43
+            else:
44
+                trellis.pixels[state] = OFF
45
+
46
+for i in range(16):
47
+    states[i] = False
48
+    #activate rising edge events on all keys
49
+    trellis.activate_key(i, NeoTrellis.EDGE_RISING)
50
+    #activate falling edge events on all keys
51
+    trellis.activate_key(i, NeoTrellis.EDGE_FALLING)
52
+    #set all keys to trigger the blink callback
53
+    trellis.callbacks[i] = toggle
54
+
55
+"""Start shortcut processing. Run forever."""
56
+while True:
57
+    for switch, switch_in in enumerate(switch_ins):
58
+        trellis.sync()
59
+        if not switch_in.value:
60
+            # If switch is pressed, it's pulled low. Debounce by waiting for bounce time.
61
+            time.sleep(BOUNCE_SECS)
62
+            print('switch: ', switch)
63
+            print(gc.mem_free())
64
+            kbd.send(Keycode.LEFT_GUI, Keycode.TAB)
65
+
66
+            # Wait for switch to be released.
67
+            while not switch_in.value:
68
+                pass

Loading…
Cancel
Save