Skip to content

Commit 3309034

Browse files
committed
Add Pi pin options, fixes.
1 parent 5aede71 commit 3309034

File tree

3 files changed

+41
-18
lines changed
  • NeoKey_MX_and_CHOC_Breakouts/CircuitPython

3 files changed

+41
-18
lines changed

NeoKey_MX_and_CHOC_Breakouts/CircuitPython/HID/code.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5-
"""NeoKey Breakout HID Demo"""
5+
"""
6+
NeoKey Breakout HID Demo
7+
8+
WILL NOT WORK ON RASPBERRY PI
9+
"""
610

711
import time
812
import board
@@ -41,16 +45,16 @@
4145
# therefore the number of key pins listed.
4246
NUM_PIXELS = len(KEY_PINS)
4347

44-
# Create keyboard object.
45-
time.sleep(1) # Delay to avoid a race condition on some systems.
46-
keyboard = Keyboard(usb_hid.devices)
47-
4848
# Create NeoPixel object.
4949
pixels = neopixel.NeoPixel(PIXEL_PIN, NUM_PIXELS, brightness=BRIGHTNESS)
5050

5151
# Create keypad object.
5252
keys = keypad.Keys(KEY_PINS, value_when_pressed=False, pull=True)
5353

54+
# Create keyboard object.
55+
time.sleep(1) # Delay to avoid a race condition on some systems.
56+
keyboard = Keyboard(usb_hid.devices)
57+
5458
while True:
5559
# Begin getting key events.
5660
event = keys.events.get()

NeoKey_MX_and_CHOC_Breakouts/CircuitPython/NeoPixel_Rainbow_Press/code.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,22 @@
1616
# 1 is maximum brightness. Defaults to 0.3.
1717
BRIGHTNESS = 0.3
1818

19-
# NeoPixel and key switch pins. Update to match your wiring setup. If adding more
20-
# NeoKey breakouts, add the pins to `KEY_PINS` in the same format as the two shown.
21-
PIXEL_PIN = board.A3
22-
KEY_PINS = (
23-
board.A1,
24-
board.A2,
25-
)
19+
# NeoPixel and key switch pins. If using different pins, update to match your wiring setup.
20+
# pylint: disable=simplifiable-condition
21+
# Check to see if a Raspberry Pi is present, and set the appropriate pins.
22+
if "CE0" and "CE1" in dir(board): # These pins are Pi-specific.
23+
PIXEL_PIN = board.D18
24+
KEY_PINS = (
25+
board.D4,
26+
board.D17,
27+
)
28+
# Otherwise, assume a microcontroller, and set the appropriate pins.
29+
else:
30+
PIXEL_PIN = board.A3
31+
KEY_PINS = (
32+
board.A1,
33+
board.A2,
34+
)
2635

2736
# --- SETUP AND CODE ---
2837
# Number of NeoPixels. This will always match the number of breakouts and

NeoKey_MX_and_CHOC_Breakouts/CircuitPython/NeoPixel_Random_Color_Press/code.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@
1515
# 1 is maximum brightness. Defaults to 0.3.
1616
BRIGHTNESS = 0.3
1717

18-
# NeoPixel and key switch pins. Update to match your wiring setup.
19-
PIXEL_PIN = board.A3
20-
KEY_PINS = (
21-
board.A1,
22-
board.A2,
23-
)
18+
# NeoPixel and key switch pins. If using different pins, update to match your wiring setup.
19+
# pylint: disable=simplifiable-condition
20+
# Check to see if a Raspberry Pi is present, and set the appropriate pins.
21+
if "CE0" and "CE1" in dir(board): # These pins are Pi-specific.
22+
PIXEL_PIN = board.D18
23+
KEY_PINS = (
24+
board.D4,
25+
board.D17,
26+
)
27+
# Otherwise, assume a microcontroller, and set the appropriate pins.
28+
else:
29+
PIXEL_PIN = board.A3
30+
KEY_PINS = (
31+
board.A1,
32+
board.A2,
33+
)
2434

2535
# --- SET UP AND CODE ---
2636
# Number of NeoPixels. This will always match the number of breakouts and

0 commit comments

Comments
 (0)