from machine import Pin
import time
boton = Pin(4,Pin.IN, Pin.PULL_UP)
def boton_presionado(pin, debounce_ms=20):
if pin.value()==0:
time.sleep_ms(debounce_ms)
if pin.value()==0:
while pin.value==0:
pass
return True
return False
while True:
if boton_presionado(boton):
print("Botón detectado")