我使用的是一个雷达传感器,它根据检测到的物体的速度提供方波。我想用方波信号的变化频率来计算物体的速度。下面的代码给出了频率,但我的问题是,即使在gpio引脚上没有输入信号,代码也会继续打印最后一个值。如何将其设置为零或停止打印上一个值。
import time
import pigpio
import read_PWM
PWM_GPIO = 21
SAMPLE_TIME = 1.0
pi = pigpio.pi()
p = read_PWM.reader(pi, PWM_GPIO)
while True:
time.sleep(SAMPLE_TIME)
f = p.frequency()
pw = p.pulse_width()
dc = p.duty_cycle()
print(f)发布于 2019-10-30 14:38:51
您可以创建一个非门,当GPIO引脚没有信号时,它会打开。
然后,您可以将您的代码更改为:
import time
import pigpio
import read_PWM
PWM_GPIO = 21
SAMPLE_TIME = 1.0
pi = pigpio.pi()
p = read_PWM.reader(pi, PWM_GPIO)
p2 = read_(whateverthisimplementations HIGH, LOW basic read is)
while True:
time.sleep(SAMPLE_TIME)
f = p.frequency()
pw = p.pulse_width()
dc = p.duty_cycle()
if p2 != HIGH:
print(f)https://stackoverflow.com/questions/58619752
复制相似问题