from machine import Pin, I2C
import ssd1306
import time
# Configura el bus I2C y la pantalla OLED
i2c = I2C(-1, Pin(22), Pin(21))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
contador = 0
interruptor_ascendente = Pin(2, Pin.IN, Pin.PULL_UP)
interruptor_descendente = Pin(15, Pin.IN, Pin.PULL_UP)
reiniciar_contador = Pin(4, Pin.IN, Pin.PULL_UP)
while True:
if not interruptor_ascendente.value():
contador += 1
elif not interruptor_descendente.value():
contador -= 1
elif not reiniciar_contador.value():
contador = 0
oled.fill(0)
oled.text("Contador:", 0, 0)
oled.text(str(contador), 80, 0)
oled.show()
time.sleep(0.1)