import machine

tcounter = 0

p1 = machine.Pin(18)
p1.init(p1.OUT)
p1.value(1)

def tcb(timer):
    global tcounter
    if tcounter & 1:
        p1.value(0)
    else:
        p1.value(1)
    tcounter += 1
    if (tcounter % 100) == 0:
        print("[tcb] timer: {} counter: {}".format(timer.timernum(), tcounter))

# t1.deinit() # if it is used

t1 = machine.Timer(2)
t1.init(period=20, mode=t1.PERIODIC, callback=tcb)

import machine

tcounter = 0

p1 = machine.Pin(18)
p1.init(p1.OUT)
p1.value(1)

def tcb(timer):
    global tcounter
    if tcounter & 1:
        p1.value(0)
    else:
        p1.value(1)
    tcounter += 1
    if (tcounter % 100) == 0:
        print("[tcb] timer: {} counter: {}".format(timer.timernum(), tcounter))

# t1.deinit() # if it is used

t1 = machine.Timer(2)
t1.init(period=20, mode=t1.PERIODIC, callback=tcb)

# t1.deinit() # if it is used