Skip to content

Commit c0435e5

Browse files
authored
Merge pull request adafruit#1524 from adafruit/qtpy_lemon_keypad
Code for Lemon Keypad
2 parents 907ffd0 + 7f08b50 commit c0435e5

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

QT_Py_RP2040_Lemon_Keypad/code.py

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import time
2+
import digitalio
3+
import board
4+
import usb_hid
5+
import neopixel
6+
from adafruit_hid.consumer_control import ConsumerControl
7+
from adafruit_hid.consumer_control_code import ConsumerControlCode
8+
from adafruit_led_animation.animation.pulse import Pulse
9+
from adafruit_led_animation.animation.solid import Solid
10+
from adafruit_led_animation.group import AnimationGroup
11+
from adafruit_led_animation.sequence import AnimationSequence
12+
13+
from adafruit_led_animation.color import WHITE, BLACK
14+
15+
pixel_pin = board.A3
16+
num_pixels = 7
17+
18+
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=.3, auto_write=False)
19+
internal_pixel = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=1, auto_write=False)
20+
21+
# The button pins we'll use, each will have an internal pullup
22+
buttonpins = [board.A0, board.A1, board.A2, board.D8, board.D9, board.D10]
23+
24+
# The keycode sent for each button, will be paired with a control key
25+
buttonkeys = [
26+
ConsumerControlCode.PLAY_PAUSE,
27+
ConsumerControlCode.FAST_FORWARD,
28+
ConsumerControlCode.VOLUME_INCREMENT,
29+
ConsumerControlCode.MUTE,
30+
ConsumerControlCode.VOLUME_DECREMENT,
31+
ConsumerControlCode.REWIND
32+
]
33+
34+
# the keyboard object!
35+
cc = ConsumerControl(usb_hid.devices)
36+
# our array of button objects
37+
buttons = []
38+
39+
# make all pin objects, make them inputs w/pullups
40+
for pin in buttonpins:
41+
button = digitalio.DigitalInOut(pin)
42+
button.direction = digitalio.Direction.INPUT
43+
button.pull = digitalio.Pull.UP
44+
buttons.append(button)
45+
46+
animations = AnimationSequence(
47+
AnimationGroup(
48+
Pulse(pixels, speed=0.05, color=WHITE, period=6),
49+
Solid(internal_pixel,color=BLACK),
50+
),
51+
)
52+
53+
print("Waiting for button presses")
54+
55+
while True:
56+
# animate neopixel jewel
57+
animations.animate()
58+
# check each button
59+
for button in buttons:
60+
if not button.value: # pressed?
61+
i = buttons.index(button)
62+
63+
print("Button #%d Pressed" % i)
64+
65+
while not button.value:
66+
pass # wait for it to be released!
67+
# type the keycode!
68+
k = buttonkeys[i] # get the corresp. keycode
69+
cc.send(k)
70+
time.sleep(0.01)

0 commit comments

Comments
 (0)