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