from machine import Pin
import time
# Configure the onboard LED pin as an output.
led = Pin(38, Pin.OUT)
# Configure the button pin as an input with an internal pull-up resistor.
button = Pin(47, Pin.IN)
print("Button and LED Example Running")
while True:
print(button.value())
# Check if the button is pressed.
# A pressed button will read a value of 0 (LOW) due to the pull-up resistor.
if button.value() == 1:
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