Skip to content

Commit 1f9f69d

Browse files
authored
Merge pull request #1590 from kattni/macropad-code
Adding MacroPad code.
2 parents e79242a + 9ebd2f4 commit 1f9f69d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""CircuitPython Digital Input example for MacroPad"""
2+
import board
3+
import digitalio
4+
5+
led = digitalio.DigitalInOut(board.LED)
6+
led.direction = digitalio.Direction.OUTPUT
7+
8+
button = digitalio.DigitalInOut(board.BUTTON)
9+
button.switch_to_input(pull=digitalio.Pull.UP)
10+
11+
while True:
12+
if not button.value:
13+
led.value = True
14+
else:
15+
led.value = False

Adafruit_MacroPad/MacroPad/code.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Keypad and rotary encoder example for Adafruit MacroPad"""
2+
import board
3+
import digitalio
4+
import rotaryio
5+
import neopixel
6+
import keypad
7+
from _pixelbuf import colorwheel
8+
9+
10+
key_pins = (board.KEY1, board.KEY2, board.KEY3, board.KEY4, board.KEY5, board.KEY6,
11+
board.KEY7, board.KEY8, board.KEY9, board.KEY10, board.KEY11, board.KEY12)
12+
keys = keypad.Keys(key_pins, value_when_pressed=False, pull=True)
13+
14+
encoder = rotaryio.IncrementalEncoder(board.ROTA, board.ROTB)
15+
button = digitalio.DigitalInOut(board.BUTTON)
16+
button.switch_to_input(pull=digitalio.Pull.UP)
17+
18+
pixels = neopixel.NeoPixel(board.NEOPIXEL, 12, brightness=0.2)
19+
20+
last_position = None
21+
while True:
22+
if not button.value:
23+
pixels.brightness = 1.0
24+
else:
25+
pixels.brightness = 0.2
26+
27+
position = encoder.position
28+
if last_position is None or position != last_position:
29+
print("Rotary:", position)
30+
last_position = position
31+
32+
color_value = (position * 2) % 255
33+
34+
event = keys.events.get()
35+
if event:
36+
print(event)
37+
if event.pressed:
38+
pixels[event.key_number] = colorwheel(color_value)
39+
else:
40+
pixels[event.key_number] = 0

0 commit comments

Comments
 (0)