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) states = ( (0,0), (1,0), (1,1), (0,1) ) old_state = 0 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() state = states.index((value_a, value_b)) if (state - old_state == 1) or (state == 0 and old_state == 3): count += 1 print('+'); print_lcd(count) old_state = state elif (state - old_state == -1) or (state == 3 and old_state == 0): count -= 1 print('-'); print_lcd(count) old_state = state