Skip to content

Commit 0df8a1c

Browse files
committed
first commit
1 parent 90710f2 commit 0df8a1c

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

Deco_Keypad/code.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2021 John Park for Adafruit
2+
#
3+
# SPDX-License-Identifier: MIT
4+
# Deco Keypad
5+
6+
7+
import time
8+
import board
9+
from digitalio import DigitalInOut, Pull
10+
from adafruit_debouncer import Debouncer
11+
import usb_hid
12+
from adafruit_hid.keyboard import Keyboard
13+
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
14+
from adafruit_hid.keycode import Keycode
15+
import neopixel
16+
17+
print("- Deco Keypad -")
18+
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
19+
20+
# ----- Keymap ----- #
21+
# change as needed, e.g. capital A (Keycode.SHIFT, Keycode.A)
22+
switch_a_output = Keycode.Z
23+
switch_b_output = Keycode.X
24+
25+
# ----- Keyboard setup ----- #
26+
keyboard = Keyboard(usb_hid.devices)
27+
keyboard_layout = KeyboardLayoutUS(keyboard) # We're in the US :)
28+
29+
# ----- Key setup ----- #
30+
switch_a_in = DigitalInOut(board.D5)
31+
switch_b_in = DigitalInOut(board.D6)
32+
switch_a_in.pull = Pull.UP
33+
switch_b_in.pull = Pull.UP
34+
switch_a = Debouncer(switch_a_in)
35+
switch_b = Debouncer(switch_b_in)
36+
37+
# ----- NeoPixel setup ----- #
38+
MAGENTA = 0xFF00FF
39+
CYAN = 0x0088DD
40+
WHITE = 0xCCCCCC
41+
BLACK = 0x000000
42+
43+
pixel_pin = board.D9
44+
pixels = neopixel.NeoPixel(pixel_pin, 2, brightness=1.0)
45+
pixels.fill(BLACK)
46+
time.sleep(0.3)
47+
pixels.fill(WHITE)
48+
time.sleep(0.3)
49+
pixels.fill(BLACK)
50+
time.sleep(0.3)
51+
pixels[0] = MAGENTA
52+
pixels[1] = CYAN
53+
54+
55+
while True:
56+
switch_a.update() # Debouncer checks for changes in switch state
57+
switch_b.update()
58+
59+
if switch_a.fell:
60+
keyboard.press(switch_a_output)
61+
pixels[0] = WHITE
62+
if switch_a.rose:
63+
keyboard.release(switch_a_output)
64+
pixels[0] = MAGENTA
65+
66+
if switch_b.fell:
67+
keyboard.press(switch_b_output)
68+
pixels[1] = WHITE
69+
if switch_b.rose:
70+
keyboard.release(switch_b_output)
71+
pixels[1] = CYAN

0 commit comments

Comments
 (0)