你好,可否帮我看看这程序哪里有错误为啥输出的了time_start却输出不了duration
import time, pyb
from pyb import Pin, ExtInt
counter=0
def count(line):
global counter
counter += 1
if counter == 1:
time_start = pyb.millis()
print(time_start)
if counter == 2:
duration = pyb.elapsed_millis(time_start)
print(duration)
counter = 0
ext = ExtInt(Pin('P5'), ExtInt.IRQ_RISING_FALLING, Pin.PULL_UP, count)
while True:
pass
你这个程序是做什么的
就是检测到上升沿开始计时,检测到下降沿停止计时,得到高电平的时间
下面的代码,把P5置高,再断开就可以看到效果。
import time, pyb
from pyb import Pin, ExtInt
time_start = 0
duration = 0
value = 0
def pulse_in(line):
global time_start
global time_delta
global value
value = Pin('P5').value()
if value:
time_start = pyb.millis()
print("time start:",time_start)
else:
duration = pyb.elapsed_millis(time_start)
print('duration: ', duration)
ext = ExtInt(Pin('P5'), ExtInt.IRQ_RISING_FALLING, Pin.PULL_DOWN, pulse_in)
while True:
pass谢谢。。解决了哈哈