回复: [如何做多个软定时器 通过中断方式,计时器只要使能就能自动计时,不能用sleep 主程序都瘫痪了?](/topic/1710/如何做多个软定时器-通import pyb,time
tim_3 = pyb.Timer(3) # create a timer object using timer 4
tim_3.init(freq=2) # trigger at 2Hz
tim_2 = pyb.Timer(4)
tim_2.init(freq=1/30)
i=0
time_count_1=0
def jishi(Timer):
print('时间计时半分钟')
def led_blink(timer):
pyb.LED(1).toggle()
print(time_count_1)
def hand_reset(timer):
print('手臂复位')
tim_3.callback(led_blink)
tim_2.callback(jishi)
while True:
time.sleep(1000)
i+=1
print(i)
s=i%60
if s==0:
print('1秒到了')
过中断方式-计时器只要使能就能自动计时-不能用sleep-主程序都瘫痪了)