Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: Copyright (c) 2021 Kattni Rembor for Adafruit Industries
2#
3# SPDX-License-Identifier: Unlicense
4"""
5Simpletest demo for MacroPad. Prints the key pressed, the relative position of the rotary
6encoder, and the state of the rotary encoder switch to the serial console.
7"""
8import time
9from adafruit_macropad import MacroPad
10
11macropad = MacroPad()
12
13while True:
14 key_event = macropad.keys.events.get()
15 if key_event and key_event.pressed:
16 print("Key pressed: {}".format(key_event.key_number))
17 print("Encoder: {}".format(macropad.encoder))
18 print("Encoder switch: {}".format(macropad.encoder_switch))
19 time.sleep(0.4)
1# SPDX-FileCopyrightText: Copyright (c) 2021 Kattni Rembor for Adafruit Industries
2#
3# SPDX-License-Identifier: Unlicense
4"""
5Grid layout demo for MacroPad. Displays the key pressed in a grid matching the key layout on the
6built-in display.
7"""
8import displayio
9import terminalio
10from adafruit_display_text import bitmap_label as label
11from adafruit_displayio_layout.layouts.grid_layout import GridLayout
12from adafruit_macropad import MacroPad
13
14macropad = MacroPad()
15
16main_group = displayio.Group()
17macropad.display.show(main_group)
18title = label.Label(
19 y=4,
20 font=terminalio.FONT,
21 color=0x0,
22 text=" KEYPRESSES ",
23 background_color=0xFFFFFF,
24)
25layout = GridLayout(x=0, y=10, width=128, height=54, grid_size=(3, 4), cell_padding=1)
26labels = []
27for _ in range(12):
28 labels.append(label.Label(terminalio.FONT, text=""))
29
30for index in range(12):
31 x = index % 3
32 y = index // 3
33 layout.add_content(labels[index], grid_position=(x, y), cell_size=(1, 1))
34
35main_group.append(title)
36main_group.append(layout)
37
38while True:
39 key_event = macropad.keys.events.get()
40 if key_event:
41 if key_event.pressed:
42 labels[key_event.key_number].text = "KEY{}".format(key_event.key_number)
43 else:
44 labels[key_event.key_number].text = ""