我已经将流量传感器与raspberry PI连接。我希望tkinter gui上的读数每秒更新一次。请帮助我编写代码
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
flowin =7
GPIO.setup(7,GPIO.IN)
rate=0
seconds=0
pulse=550
time_new = 0.0
#numlist=list()
while True:
y=2
time_new = time.time() + 1
rate_cnt = 0
#y=numlist.append(x)
while time.time() <= time_new:
x=GPIO.input(flowin)
if y!=x:
if GPIO.input(flowin)!= 0:
rate+= 1
y=x
seconds+=1
litre=rate/pulse
minutes=seconds/60
flowrate=litre/minutes
#print("flowrate",flowrate)
您可以使用
thread
读取传感器读数,并更新与tkinterLabel
关联的StringVar
以显示flowrate
以下是基于您的代码的示例:
相关问题 更多 >
编程相关推荐