File tree Expand file tree Collapse file tree
NeoKey_MX_and_CHOC_Breakouts/CircuitPython
NeoPixel_Random_Color_Press Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
711import time
812import board
4145# therefore the number of key pins listed.
4246NUM_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.
4949pixels = neopixel .NeoPixel (PIXEL_PIN , NUM_PIXELS , brightness = BRIGHTNESS )
5050
5151# Create keypad object.
5252keys = 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+
5458while True :
5559 # Begin getting key events.
5660 event = keys .events .get ()
Original file line number Diff line number Diff line change 1616# 1 is maximum brightness. Defaults to 0.3.
1717BRIGHTNESS = 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
Original file line number Diff line number Diff line change 1515# 1 is maximum brightness. Defaults to 0.3.
1616BRIGHTNESS = 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
You can’t perform that action at this time.
0 commit comments