from machine import Pin
import time
# Define GPIO pins
led_pin = Pin(2, Pin.OUT)
switch_pin = Pin(4, Pin.IN)
# Main loop
while True:
# initial state
led_pin.off()
# Read the state of the switch
switch_state = switch_pin.value()
print(switch_state)
#tekan =1
if switch_state ==1:
led_pin.on()
time.sleep(1)
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4