Skip to content

Commit d24c370

Browse files
committed
Adding digital input single NeoPixel example
1 parent d6982a1 commit d24c370

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""CircuitPython Digital Input example - Blinking a built-in NeoPixel LED using a button switch.
2+
3+
Update BUTTON_PIN to the pin to which you have connected the button (in the case of an external
4+
button), or to the pin connected to the built-in button (in the case of boards with built-in
5+
buttons).
6+
7+
For example:
8+
If you connected a button switch to D1, change BUTTON_PIN to D1.
9+
If using a QT Py RP2040, to use button A, change BUTTON_PIN to BUTTON.
10+
"""
11+
import board
12+
import digitalio
13+
import neopixel
14+
15+
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
16+
17+
button = digitalio.DigitalInOut(board.BUTTON_PIN)
18+
button.switch_to_input(pull=digitalio.Pull.UP)
19+
20+
while True:
21+
if not button.value:
22+
pixel.fill((255, 0, 0))
23+
else:
24+
pixel.fill(0)

0 commit comments

Comments
 (0)