硬體上有四組 timer 0/1/2/3 可使用
# 範例十五:
# timer 用法,讓 led 每隔一秒閃爍一次
# 需要的 module :
# FB : https://www.facebook.com/mason.chen.1420
from machine import Pin
from machine import Timer
cnt = None
# Describe this function...
def timer1_func():
global cnt
if cnt == 0:
Pin(12, Pin.OUT).value(0)
cnt = 1
else:
Pin(12, Pin.OUT).value(1)
cnt = 0
cnt = 0
timer1 = Timer(1)
timer1.init(period=1000, mode=Timer.PERIODIC, callback=lambda t:timer1_func())