from machine import Pin
import time
# Configure the onboard LED pin as an output.
led = Pin(42, Pin.OUT)
# Configure the button pin as an input with an internal pull-up resistor.
button = Pin(47, Pin.IN, Pin.PULL_UP)
print("Button and LED Example Running")
while True:
# Check if the button is pressed.
# A pressed button will read a value of 0 (LOW) due to the pull-up resistor.
if not button.value():
led.value(1) # Turn the LED ON
print("Button Pressed - LED ON")
# Debounce delay to prevent multiple readings from a single press
time.sleep_ms(200)
else:
led.value(0) # Turn the LED OFF
Loading
esp32-s3-devkitc-1
esp32-s3-devkitc-1