-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.py
More file actions
45 lines (38 loc) · 1.28 KB
/
code.py
File metadata and controls
45 lines (38 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import board
from kmk.kmk_keyboard import KMKKeyboard
from kmk.keys import KC
from kmk.scanners.keypad import KeysScanner
import kmk.extensions.neopixel
# Your `main.ato` file shows 4 switches connected to GPIOs 0, 1, 2, and 3.
# We'll configure these as direct-wired keys.
key_pins = (board.IO0, board.IO1, board.IO2, board.IO3)
keyboard = KMKKeyboard()
# Use the KeysScanner for direct pin connections.
# This assumes the other side of your switch is connected to ground.
# `pull=True` enables the internal pull-up resistors on the pins.
keyboard.matrix = KeysScanner(
pins=key_pins,
value_when_pressed=False,
pull=True,
)
# Define your keymap. This is a simple 4-key layout.
# You can use any keycodes from the KMK library.
# For example: KC.A, KC.LCTRL, KC.MEDIA_PLAY_PAUSE, etc.
keyboard.keymap = [
[KC.A, KC.B, KC.C, KC.D]
]
# Your `main.ato` also defines 4 SK6805 LEDs connected to GPIO 4.
# Let's enable the Neopixel extension to control them.
neopixel_ext = kmk.extensions.neopixel.Neopixel(
# The data pin for the NeoPixel strip
pin=board.IO4,
# Number of LEDs
n_pixels=4,
# You can adjust hue, saturation, and brightness
hue=120, # Green
sat=255,
val=128,
)
keyboard.extensions.append(neopixel_ext)
if __name__ == '__main__':
keyboard.go()