Skip to content

Commit 54d0055

Browse files
committed
Adding demos.
1 parent 39097f3 commit 54d0055

7 files changed

+70
-7
lines changed

adafruit_macropad.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ def keys(self):
292292
macropad = MacroPad()
293293
294294
while True:
295-
event = macropad.keys.events.get()
296-
if event:
297-
print(event)
295+
key_event = macropad.keys.events.get()
296+
if key_event:
297+
print(key_event)
298298
"""
299299
return self._keys
300300

@@ -748,9 +748,9 @@ def display_text(
748748
text_lines = macropad.display_text(title="MacroPad Info")
749749
750750
while True:
751-
event = macropad.keys.events.get()
752-
if event:
753-
text_lines[0].text = "Key {} pressed!".format(event.key_number)
751+
key_event = macropad.keys.events.get()
752+
if key_event:
753+
text_lines[0].text = "Key {} pressed!".format(key_event.key_number)
754754
text_lines[1].text = "Rotary encoder {}".format(macropad.encoder)
755755
text_lines[2].text = "Encoder switch: {}".format(macropad.encoder_switch)
756756
text_lines.show()

examples/blinka.bmp

1.06 KB
Binary file not shown.

examples/blinka.bmp.license

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2021 Kattni Rembor for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense

examples/macropad_display_image.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2021 Kattni Rembor for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
"""
5+
MacroPad display image demo. Displays a bitmap image on the built-in display.
6+
"""
7+
from adafruit_macropad import MacroPad
8+
9+
macropad = MacroPad()
10+
11+
while True:
12+
macropad.display_image("blinka.bmp")

examples/macropad_rainbow_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
"""
99
import displayio
1010
import terminalio
11+
from rainbowio import colorwheel
1112
from adafruit_display_text import bitmap_label as label
1213
from adafruit_displayio_layout.layouts.grid_layout import GridLayout
1314
from adafruit_macropad import MacroPad
14-
from rainbowio import colorwheel
1515

1616
macropad = MacroPad()
1717

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2021 Kattni Rembor for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
"""
5+
Simpletest demo for MacroPad. Displays the key pressed, the relative position of the rotary
6+
encoder, and the state of the rotary encoder switch to the built-in display. Note that the key
7+
pressed line does not appear until a key is pressed.
8+
"""
9+
from adafruit_macropad import MacroPad
10+
11+
macropad = MacroPad()
12+
13+
text_lines = macropad.display_text(title="MacroPad Info")
14+
15+
while True:
16+
key_event = macropad.keys.events.get()
17+
if key_event and key_event.pressed:
18+
text_lines[0].text = "Key {} pressed!".format(key_event.key_number)
19+
text_lines[1].text = "Rotary encoder {}".format(macropad.encoder)
20+
text_lines[2].text = "Encoder switch: {}".format(macropad.encoder_switch)
21+
text_lines.show()

examples/macropad_tone_keypad.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: Unlicense
4+
"""
5+
MacroPad tone demo. Plays a different tone for each key pressed and lights up each key a different
6+
color while the key is pressed.
7+
"""
8+
from rainbowio import colorwheel
9+
from adafruit_macropad import MacroPad
10+
11+
macropad = MacroPad()
12+
13+
tones = [196, 220, 246, 262, 294, 330, 349, 392, 440, 494, 523, 587]
14+
15+
while True:
16+
key_event = macropad.keys.events.get()
17+
18+
if key_event:
19+
if key_event.pressed:
20+
macropad.pixels[key_event.key_number] = colorwheel(
21+
int(255 / 12) * key_event.key_number
22+
)
23+
macropad.start_tone(tones[key_event.key_number])
24+
25+
else:
26+
macropad.pixels.fill((0, 0, 0))
27+
macropad.stop_tone()

0 commit comments

Comments
 (0)