实验名称:定时器
版本:v1.0
日期:20230824
作者:python-lingdu
说明:通过定时器让LED周期性每秒闪烁1次
实验平台:开发板
'''
from machine import Timer,Pin
LED=Pin(Pin.GPIO24,Pin.OUT) #构建led对象,GPIO24,输出
#共4个定时器,编号0~3
timer0 = Timer(Timer.Timer0)
state = 0
def fun(timer0):
global state
state = not state
LED.write(state)
#开启定时器,周期1秒
timer0.start(period=1000,mode=Timer.PERIODIC,callback=fun)