File tree Expand file tree Collapse file tree 3 files changed +41
-18
lines changed
NeoKey_MX_and_CHOC_Breakouts/CircuitPython
NeoPixel_Random_Color_Press Expand file tree Collapse file tree 3 files changed +41
-18
lines changed Original file line number Diff line number Diff line change 2
2
#
3
3
# SPDX-License-Identifier: MIT
4
4
5
- """NeoKey Breakout HID Demo"""
5
+ """
6
+ NeoKey Breakout HID Demo
7
+
8
+ WILL NOT WORK ON RASPBERRY PI
9
+ """
6
10
7
11
import time
8
12
import board
41
45
# therefore the number of key pins listed.
42
46
NUM_PIXELS = len (KEY_PINS )
43
47
44
- # Create keyboard object.
45
- time .sleep (1 ) # Delay to avoid a race condition on some systems.
46
- keyboard = Keyboard (usb_hid .devices )
47
-
48
48
# Create NeoPixel object.
49
49
pixels = neopixel .NeoPixel (PIXEL_PIN , NUM_PIXELS , brightness = BRIGHTNESS )
50
50
51
51
# Create keypad object.
52
52
keys = keypad .Keys (KEY_PINS , value_when_pressed = False , pull = True )
53
53
54
+ # Create keyboard object.
55
+ time .sleep (1 ) # Delay to avoid a race condition on some systems.
56
+ keyboard = Keyboard (usb_hid .devices )
57
+
54
58
while True :
55
59
# Begin getting key events.
56
60
event = keys .events .get ()
Original file line number Diff line number Diff line change 16
16
# 1 is maximum brightness. Defaults to 0.3.
17
17
BRIGHTNESS = 0.3
18
18
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
+ )
26
35
27
36
# --- SETUP AND CODE ---
28
37
# Number of NeoPixels. This will always match the number of breakouts and
Original file line number Diff line number Diff line change 15
15
# 1 is maximum brightness. Defaults to 0.3.
16
16
BRIGHTNESS = 0.3
17
17
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
+ )
24
34
25
35
# --- SET UP AND CODE ---
26
36
# Number of NeoPixels. This will always match the number of breakouts and
You can’t perform that action at this time.
0 commit comments