from machine import Pin
import utime
#Pin del botón
boton = Pin(27, Pin.IN, Pin.PULL_DOWN)
# Contador de pulsaciones
contador = 0
# Tiempo mínimo entre pulsaciones válidas (en ms)
tiempo_antirrebote = 200
ultimo_tiempo = 0
print("Contador iniciado. Pulsa el botón.")
while True:
if boton.value() == 1:
tiempo_actual = utime.ticks_ms()
# Verifica si ha pasado suficiente tiempo desde la última pulsación
if utime.ticks_diff(tiempo_actual, ultimo_tiempo) > tiempo_antirrebote:
contador += 1
print("Pulsación detectada. Total:", contador)
ultimo_tiempo = tiempo_actual
# Espera hasta que el botón se suelte
while boton.value() == 1:
pass