from time import sleep_ms, ticks_ms from machine import I2C, Pin from esp8266_i2c_lcd import I2cLcd _init() DEFAULT_I2C_ADDR = 0x3F # Или 0x27 в зависимости от модели микросхемы на плате encA = Pin(13, Pin.IN) encB = Pin(12, Pin.IN) old_value_a = 1 count = 0 def print_lcd(data): lcd.clear() lcd.putstr(str(data)) i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16) lcd.backlight_on() while True: value_a = encA.value() value_b = encB.value() if value_a != old_value_a: if (value_a and value_b) or (not value_a and not value_b): print('+') count += 1 print_lcd(count) elif (not value_a and value_b) or (value_a and not value_b): print('-') count -= 1 print_lcd(count) old_value_a = value_a