Adding digital input single NeoPixel example
This commit is contained in:
parent
d6982a12a2
commit
d24c370faa
1 changed files with 24 additions and 0 deletions
24
CircuitPython_Templates/digital_input_one_neopixel.py
Normal file
24
CircuitPython_Templates/digital_input_one_neopixel.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
"""CircuitPython Digital Input example - Blinking a built-in NeoPixel LED using a button switch.
|
||||
|
||||
Update BUTTON_PIN to the pin to which you have connected the button (in the case of an external
|
||||
button), or to the pin connected to the built-in button (in the case of boards with built-in
|
||||
buttons).
|
||||
|
||||
For example:
|
||||
If you connected a button switch to D1, change BUTTON_PIN to D1.
|
||||
If using a QT Py RP2040, to use button A, change BUTTON_PIN to BUTTON.
|
||||
"""
|
||||
import board
|
||||
import digitalio
|
||||
import neopixel
|
||||
|
||||
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
|
||||
|
||||
button = digitalio.DigitalInOut(board.BUTTON_PIN)
|
||||
button.switch_to_input(pull=digitalio.Pull.UP)
|
||||
|
||||
while True:
|
||||
if not button.value:
|
||||
pixel.fill((255, 0, 0))
|
||||
else:
|
||||
pixel.fill(0)
|
||||
Loading…
Reference in a new issue