请教:1s显示一次输入的脉冲数,外部中断可以累加计数,加上定时器每次定时到清零再计数显示实现不了。哥伦布开发板
from pyb import Timer,ExtInt,delay
from machine import Pin
counter=0
def fun(ext):
global counter
counter+=1
tim_flag = 0
def count(tim):
global tim_flag
tim_flag = 1
tim = pyb.Timer(3,freq=1000) #1min刷新一次
tim.callback(count)
while True:
#执行按钮触发的任务
if tim_flag == 1:
print(counter)
tim_flag = 0
counter=0
ext = ExtInt(Pin('B1'), ExtInt.IRQ_RISING, Pin.PULL_UP, fun)
|