from machine import Pin, I2C
import utime
from i2c_lcd import I2cLcd
#Pin del botón
boton = Pin(11, Pin.IN, Pin.PULL_DOWN)
#Pin
i2c = I2C(0, sda=Pin(20), scl=Pin(21), freq=400000)
direcciones = i2c.scan()
if len(direcciones) == 0:
print("No se encontró LCD.")
while True:
pass
direccion_lcd = direcciones[0]
# Inicializa la LCD (16 columnas x 2 filas)
lcd = I2cLcd(i2c, direccion_lcd, 2, 16)
# Inicializa contador
contador = 0
tiempo_antirrebote = 200
ultimo_tiempo = 0
lcd.clear()
lcd.putstr("Contador listo")
while True:
if boton.value() == 1:
tiempo_actual = utime.ticks_ms()
if utime.ticks_diff(tiempo_actual, ultimo_tiempo) > tiempo_antirrebote:
contador += 1
lcd.clear()
lcd.putstr("Pulsaciones:\n{}".format(contador))
ultimo_tiempo = tiempo_actual
while boton.value() == 1:
pass