按特定顺序触发 PIR 传感器
在我的设计中,我有两个连接到 Raspberry Pi 的 PIR 传感器,一个用于门口的两侧。
我需要帮助,了解一旦传感器按特定顺序触发,我该如何做某事。
为了简单起见,我们将传感器称为 A 和 B。
由于它们将用于房间计数,我希望当它们按顺序 AB 触发时计数增加,当按顺序 BA 触发时计数减少。
我之前尝试过这段代码,但失败了(我知道这里没有实现 roomCount,但我正在测试预期的输出):
While True:
if GPIO.input(pir1):
if GPIO.input(pir2):
print(“AB”)
if GPIO.input(pir2):
if GPIO.input(pir1):
print(“BA”)
无论触发哪个顺序,这段代码都会不断给出输出“AB”。
任何有关此问题的帮助将不胜感激。
I have two PIR Sensors connected to a Raspberry Pi one used for either side of a doorway in my design.
I am needing help on how I can do something once the sensors are triggered in a particular order.
Lets call the sensors for simplicity A and B.
Since they will be used for room count I would like the count to increase when they are triggered in order AB and decrease when triggered in order BA.
I have tried this code earlier but it failed (I understand there is no roomCount implemented here but I was testing for expected output):
While True:
if GPIO.input(pir1):
if GPIO.input(pir2):
print(“AB”)
if GPIO.input(pir2):
if GPIO.input(pir1):
print(“BA”)
This code was constantly giving the output “AB” no matter which order they were triggered.
Any help on this issue would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试这样的事情:
希望会有所帮助。
You can try something like this:
Hope that helps.
我认为您可能会做得更好,更像是这样的伪代码:
I think you might do better with code more like this pseudo-code: