Add simple keypad macropad example
This commit is contained in:
parent
b3935350c1
commit
2a58a1797a
1 changed files with 37 additions and 0 deletions
37
Keypad_Examples/macropad_simple/code.py
Normal file
37
Keypad_Examples/macropad_simple/code.py
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
import board
|
||||||
|
import keypad
|
||||||
|
import neopixel
|
||||||
|
|
||||||
|
KEY_PINS = (
|
||||||
|
board.KEY1,
|
||||||
|
board.KEY2,
|
||||||
|
board.KEY3,
|
||||||
|
board.KEY4,
|
||||||
|
board.KEY5,
|
||||||
|
board.KEY6,
|
||||||
|
board.KEY7,
|
||||||
|
board.KEY8,
|
||||||
|
board.KEY9,
|
||||||
|
board.KEY10,
|
||||||
|
board.KEY11,
|
||||||
|
board.KEY12,
|
||||||
|
)
|
||||||
|
|
||||||
|
keys = keypad.Keys(KEY_PINS, value_when_pressed=False, pull=True)
|
||||||
|
|
||||||
|
neopixels = neopixel.NeoPixel(board.NEOPIXEL, 12, brightness=0.4)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
event = keys.events.get()
|
||||||
|
if event:
|
||||||
|
# A key transition occurred.
|
||||||
|
print(event)
|
||||||
|
|
||||||
|
if event.pressed:
|
||||||
|
# Turn the key blue when pressed
|
||||||
|
neopixels[event.key_number] = (0, 0, 255)
|
||||||
|
|
||||||
|
# This could just be `else:`,
|
||||||
|
# since event.pressed and event.released are opposites.
|
||||||
|
if event.released:
|
||||||
|
neopixels[event.key_number] = (0, 0, 0)
|
||||||
Loading…
Reference in a new issue