from machine import Timer
import time
defcallback_periodic(obj):# defined preiodic mode timeout callbackprint("Timer callback periodic test")defcallback_oneshot(obj):# defined ont shot mode timeout callbackprint("Timer callback oneshot test")print("start")
timer = Timer()# Create Timer object, driver support timer1/timer2/timer3
timer.start(timer.PERIODIC,1000, callback_periodic)# Initialize the Timer device object# Set Timer mode to preiodic mode, set timeout to 1 seconds and set callback fucntion
time.sleep(5)# Execute 5 times timeout callback in the delay time
timer.start(timer.ONE_SHOT,1000, callback_oneshot)# Reset initialize the Timer device object# Set Timer mode to one shot mode, set timeout to 1 seconds and set callback fucntion
time.sleep(5)# Execute 1 times timeout callback in the delay time
timer.deinit()# Stop and close Timer device object
太赞了,功德无量