Routine-Erklärung-02-timer_tests Timer-Test

# 定时器测试例子
#
# 这个例子测试了所有的定时器

import time
from pyb import Pin, Timer, LED

blue_led  = LED(3)

# 注意:在回调中不允许分配内存的函数
def tick(timer):
    blue_led.toggle()

print("")
for i in range(1, 18):
    try:
        print("Testing TIM%d... "%(i), end="") 
        tim = Timer(i, freq=10)     # 使用定时器4创建一个定时器对象-在1Hz触发
        tim.callback(tick)          # 将回调设置为tick函数
        time.sleep_ms(1000)
        tim.deinit()
    except ValueError as e:
        print(e)
        continue
    print("done!")

results matching ""

    No results matching ""