Add Pi pin options, fixes.
This commit is contained in:
parent
5aede71093
commit
3309034617
3 changed files with 41 additions and 18 deletions
|
|
@ -2,7 +2,11 @@
|
|||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
"""NeoKey Breakout HID Demo"""
|
||||
"""
|
||||
NeoKey Breakout HID Demo
|
||||
|
||||
WILL NOT WORK ON RASPBERRY PI
|
||||
"""
|
||||
|
||||
import time
|
||||
import board
|
||||
|
|
@ -41,16 +45,16 @@ KEY_PINS = (
|
|||
# therefore the number of key pins listed.
|
||||
NUM_PIXELS = len(KEY_PINS)
|
||||
|
||||
# Create keyboard object.
|
||||
time.sleep(1) # Delay to avoid a race condition on some systems.
|
||||
keyboard = Keyboard(usb_hid.devices)
|
||||
|
||||
# Create NeoPixel object.
|
||||
pixels = neopixel.NeoPixel(PIXEL_PIN, NUM_PIXELS, brightness=BRIGHTNESS)
|
||||
|
||||
# Create keypad object.
|
||||
keys = keypad.Keys(KEY_PINS, value_when_pressed=False, pull=True)
|
||||
|
||||
# Create keyboard object.
|
||||
time.sleep(1) # Delay to avoid a race condition on some systems.
|
||||
keyboard = Keyboard(usb_hid.devices)
|
||||
|
||||
while True:
|
||||
# Begin getting key events.
|
||||
event = keys.events.get()
|
||||
|
|
|
|||
|
|
@ -16,13 +16,22 @@ from rainbowio import colorwheel
|
|||
# 1 is maximum brightness. Defaults to 0.3.
|
||||
BRIGHTNESS = 0.3
|
||||
|
||||
# NeoPixel and key switch pins. Update to match your wiring setup. If adding more
|
||||
# NeoKey breakouts, add the pins to `KEY_PINS` in the same format as the two shown.
|
||||
PIXEL_PIN = board.A3
|
||||
KEY_PINS = (
|
||||
board.A1,
|
||||
board.A2,
|
||||
)
|
||||
# NeoPixel and key switch pins. If using different pins, update to match your wiring setup.
|
||||
# pylint: disable=simplifiable-condition
|
||||
# Check to see if a Raspberry Pi is present, and set the appropriate pins.
|
||||
if "CE0" and "CE1" in dir(board): # These pins are Pi-specific.
|
||||
PIXEL_PIN = board.D18
|
||||
KEY_PINS = (
|
||||
board.D4,
|
||||
board.D17,
|
||||
)
|
||||
# Otherwise, assume a microcontroller, and set the appropriate pins.
|
||||
else:
|
||||
PIXEL_PIN = board.A3
|
||||
KEY_PINS = (
|
||||
board.A1,
|
||||
board.A2,
|
||||
)
|
||||
|
||||
# --- SETUP AND CODE ---
|
||||
# Number of NeoPixels. This will always match the number of breakouts and
|
||||
|
|
|
|||
|
|
@ -15,12 +15,22 @@ from rainbowio import colorwheel
|
|||
# 1 is maximum brightness. Defaults to 0.3.
|
||||
BRIGHTNESS = 0.3
|
||||
|
||||
# NeoPixel and key switch pins. Update to match your wiring setup.
|
||||
PIXEL_PIN = board.A3
|
||||
KEY_PINS = (
|
||||
board.A1,
|
||||
board.A2,
|
||||
)
|
||||
# NeoPixel and key switch pins. If using different pins, update to match your wiring setup.
|
||||
# pylint: disable=simplifiable-condition
|
||||
# Check to see if a Raspberry Pi is present, and set the appropriate pins.
|
||||
if "CE0" and "CE1" in dir(board): # These pins are Pi-specific.
|
||||
PIXEL_PIN = board.D18
|
||||
KEY_PINS = (
|
||||
board.D4,
|
||||
board.D17,
|
||||
)
|
||||
# Otherwise, assume a microcontroller, and set the appropriate pins.
|
||||
else:
|
||||
PIXEL_PIN = board.A3
|
||||
KEY_PINS = (
|
||||
board.A1,
|
||||
board.A2,
|
||||
)
|
||||
|
||||
# --- SET UP AND CODE ---
|
||||
# Number of NeoPixels. This will always match the number of breakouts and
|
||||
|
|
|
|||
Loading…
Reference in a new issue