import time
import tm1637
import machine 
from machine import Pin, I2C

import micropython
micropython.alloc_emergency_exception_buf(100)

print("Hello, ESP32!")


encoder1_clk = machine.Pin(21, Pin.IN)
encoder1_dt  = machine.Pin(19, Pin.IN)

counter = 0
direction = 0
target    = 99                                    # Magic number
# Interrupt Service Routine 

# Interrupt Service Routine 
def encoder1_clk_change(change):
    global counter
    if encoder1_dt.value():
        counter += 1
        print ("a->",  counter )

def encoder1_dt_change(change):
    global counter
    if encoder1_clk.value():
        counter -= 1
        print ("      b ->",  counter)

print("Begin")
encoder1_clk.irq(handler=encoder1_clk_change, trigger=Pin.IRQ_FALLING)
encoder1_dt.irq(handler=encoder1_dt_change, trigger=Pin.IRQ_FALLING)

Counter = 0
while True:
   time.sleep(1)


4-Digit Display
4-Digit Display