from machine import I2C, Pin from esp8266_i2c_lcd import I2cLcd import time _init() DEFAULT_I2C_ADDR = 0x3F # Или 0x27 в зависимости от модели микросхемы на плате encA = Pin(13, Pin.IN) encB = Pin(12, Pin.IN) count = 0 states = ( (1,1), (0,1), (0,0), (1,0) ) old_state = 0 def print_lcd(data): lcd.clear() lcd.putstr(str(data)) def callback(p): global count global encB global encA global states global old_state value_a = encA.value() value_b = encB.value() current_state = states.index((value_a, value_b)) if (current_state - old_state == 1) or (current_state == 0 and old_state == 3): count += 1 if not (count % 2): print('+'); print_lcd(int(count/2)) old_state = current_state elif (current_state - old_state == -1) or (current_state == 3 and old_state == 0): count -= 1 if not (count % 2): print('-'); print_lcd(int(count/2)) old_state = current_state i2c = I2C(scl=Pin(5), sda=Pin(4), freq=400000) lcd = I2cLcd(i2c, DEFAULT_I2C_ADDR, 2, 16) lcd.backlight_on() encA.irq(trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING, handler=callback) encB.irq(trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING, handler=callback) while True: pass