print("Hello, World from ESP32 + MicroPython on Wokwi!")
# Wiring: Connect the LED anode → resistor → GPIO 2, and the LED cathode → GND.
# Make an LED blink on and off every half-second using a simple loop.
# from machine import Pin
# import time
# led = Pin(2, Pin.OUT)
# while True:
# led.value(1)
# time.sleep(0.5)
# led.value(0)
# time.sleep(0.5)
# Use a pushbutton to toggle the LED each time you press it — one press turns it on, the next turns it off.
from machine import Pin
import time
led = Pin(2, Pin.OUT)
btn = Pin(4, Pin.IN, Pin.PULL_UP) # idle=1, pressed=0
state = 0
last = 1
while True:
cur = btn.value()
if last == 1 and cur == 0: # falling edge
state ^= 1
led.value(state)
time.sleep(0.02) # debounce
while btn.value() == 0: # wait release
time.sleep(0.01)
last = cur
time.sleep(0.01)