import utime
import machine
from machine import I2C, Pin
from lcd_api import LcdApi
from pico_i2c_lcd import I2cLcd

I2C_ADDR     = 0x27
I2C_NUM_ROWS = 2
I2C_NUM_COLS = 16

# Test function for verifying basic functionality
print("Running test_main")
i2c = I2C(0, sda=machine.Pin(0), scl=machine.Pin(1), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)    
lcd.putstr("    Eventos:        0000")

count = 0
b1 = Pin(16, Pin.IN, Pin.PULL_UP)
b2 = Pin(17, Pin.IN, Pin.PULL_UP)

def fun_b1(pin):
    global count
    count += 1
    if count == 1001:
        count = 0
    lcd.move_to(10, 1)  # Ajusta la posición donde quieres escribir
    lcd.putstr(f"{count:04d}")

def fun_b2(pin):
    global count
    count -= 1
    if count < 0:
        count = 1000
    lcd.move_to(10, 1)  # Ajusta la posición donde quieres escribir
    lcd.putstr(f"{count:04d}")

b1.irq(trigger=Pin.IRQ_FALLING, handler=fun_b1)
b2.irq(trigger=Pin.IRQ_FALLING, handler=fun_b2)

while True:
    pass