如何解决从continuous_threading.PeriodicThread 获取特定字符串然后执行操作
我是 Python 新手。我有一个脚本,它使用从 Arduino 到 RaspBerry Pi 4 的串行通信。我正在研究一个距离监控系统。我在 Arduino 中有一个超声波距离传感器,我正在通过串行通信将读数从 Arduino 传递到树莓派。我想获得一个特定的字符串,就像传感器在 raspBerry pi 的脚本中检测到物体靠近传感器一样。我的代码是这样的:(不要担心 tkinter GUI 和所有导入,它工作正常)
ser = serial.Serial('dev/ttyACM0',19200)
val1 = 0
index = []
def readserial():
global val1
ser_bytes = ser.readline()
print(ser_bytes.rstrip())
val1 = ser_bytes
index.append(val1)
if len(index) == 1:
display1 = tk.Label(screen,text = index[0])
index.clear() # I have only one line in the GUI so it replaces the text every 0.5 interval
screen = Tk()
screen.title("Anti-collision")
t1 = continuous_threading.PeriodicThread(0.5,readserial)
t1.start()
screen.mainloop()
如果传感器检测到距离传感器更近 1 英寸的物体,并且读取器输出字符串“OBJECT CLOSER”,我想显示另一个 GUI。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。