code.py
1 # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries 2 # SPDX-License-Identifier: MIT 3 """CircuitPython Digital Input example - Blinking a built-in NeoPixel LED using a button switch. 4 5 Update BUTTON_PIN to the pin to which you have connected the button (in the case of an external 6 button), or to the pin connected to the built-in button (in the case of boards with built-in 7 buttons). 8 9 For example: 10 If you connected a button switch to D1, change BUTTON_PIN to D1. 11 If using a QT Py RP2040, to use button A, change BUTTON_PIN to BUTTON. 12 """ 13 import board 14 import digitalio 15 import neopixel 16 17 pixel = neopixel.NeoPixel(board.NEOPIXEL, 1) 18 19 button = digitalio.DigitalInOut(board.BUTTON_PIN) 20 button.switch_to_input(pull=digitalio.Pull.UP) 21 22 while True: 23 if not button.value: 24 pixel.fill((255, 0, 0)) 25 else: 26 pixel.fill((0, 0, 0))