例程讲解-09-timer_control定时器控制
# 定时器控制例子
#
# 这个例子展示了如何使用回调函数和定时器
import time
from pyb import Pin, Timer
def tick(timer): # we will receive the timer object when being called
print("Timer callback")
tim = Timer(4, freq=1) # create a timer object using timer 4 - trigger at 1Hz
tim.callback(tick) # set the callback to our tick function
while (True):
time.sleep_ms(1000)