- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当用户将双手放在 PIR 传感器上时,我无法对 2 个 PIR 传感器的逻辑进行编程以在控制台中打印消息。我已经成功地使用 GPIO、GND 将 PIR 传感器连接到树莓派,并且5v端口。我目前拥有的代码确实会在有人挥手时在控制台中打印出一条消息,但我很难修改代码以在有人在两个 PIR 传感器上挥手时打印出错误消息。
我们可以使用 GP4 和 GP17 从传感器读取输入
这是我在运行代码时收到的错误消息。
Traceback (most recent call last):
File "peter.py", line 22, in <module>
if current_state2(TRUE) and current_state(TRUE) != previous_state2(FALSE) and previous_state(FALSE):
NameError: name 'TRUE' is not defined
这是代码
import RPi.GPIO as GPIO
import time
sensor = 4
sensor2 = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor, GPIO.IN, GPIO.PUD_DOWN)
GPIO.setup(sensor2, GPIO.IN, GPIO.PUD_DOWN)
previous_state = False
current_state = False
previous_state2 = False
current_state2 = False
while True:
time.sleep(0.1)
previous_state = current_state
previous_state2 = current_state2
current_state = GPIO.input(sensor)
current_state2 = GPIO.input(sensor2)
if current_state2(TRUE) and current_state(TRUE) != previous_state2(FALSE) and previous_state(FALSE):
new_state = "HIGH" if current_state else "LOW"
new_state2 = "HIGH" if current_state2 else "LOW"
print("GPIO pin %s is %s" % (sensor, new_state, sensor2, new_state2))
程序非常简单。 Raspberry Pi GPIO 引脚允许我们使用引脚 4 作为输入;然后它可以检测 PIR 模块何时发送电源。该引脚不断检查是否有任何更改,为此使用 while True 循环。这是一个无限循环,因此程序将连续运行,除非我们使用 Ctrl + C 手动停止它。然后使用两个 bool 变量(True 或 False)表示引脚的先前状态和当前状态,先前状态就是当前状态循环之前的时间
最佳答案
在 Python 中使用“True”,而不是“TRUE”:
if True:
print("True")
else:
print("False")
同时改变:
if current_state2(TRUE) and current_state(TRUE) != previous_state2(FALSE) and previous_state(FALSE):
收件人:
if current_state2==True and current_state != previous_state2 and previous_state==False:
关于android - 名称错误 : name 'TRUE' is not defined PIR sensors,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37382525/
使用 fetchone() 命令从 MYSQL 表中得到: ('analog sensor1',60L) 那么从这个如何得到 sensor=analog sensor1 和 interval=60 通
我有一部 Yureka 手机,还有 from its specs我可以看到它至少有一个加速度计和一个陀螺仪。 我从网上查到的是TYPE_ROTATION_VECTOR需要加速度计、陀螺仪和磁力计。由于
我正在做一些增强现实应用程序,我需要方位角来计算屏幕上的某个对象位置。我尝试使用 Sensor.TYPE_ORIENTATION 获取方向数据,由于它已被弃用,我尝试了 Sensor.TYPE_MAG
我正在尝试从 Samsung Galaxy Nexus(Android 4.0)中尽可能快地读出传感器值。为此,我使用不同的传感器和采样率做了一些实验,并发现了一个非常奇怪的行为。当我仅使用 Acc-
更新: 我能够通过引入类范围静态计数器并忽略 x 数量的事件来解决我遇到的特定问题。但我仍然想知道我做错了什么:以微秒为单位用提示注册监听器,而不是使用四个给定常量之一。 我的应用程序中的一个 Act
我正在为 Microsoft Band 开发 UWP 应用程序,最近从 Band SDK ver 1.3.11121 升级到 Microsoft Band SDK ver 1.3.20115。 我注意
I'm constructing a device to measure power and display in a 16x2 LCD in a given power source. I'm
在阅读有关磁力计/磁场/“指南针”传感器的信息时,人们常说传感器倾斜补偿,例如为了获得正确的测量结果,需要使用加速度计。 (请注意,我在这里不是在谈论硬铁和软铁效应。)所有这些来源都利用二维罗盘进行澄
我正在构建一个应用程序,该应用程序必须同时将各种传感器值记录到一个 .csv 文件中(如果传感器可用)。任何人都可以提出将值插入到 csv 文件(表格形式)中的方法吗?这可能吗在单个传感器更改事件中记
我正在制作一个 Compass 应用程序,我发现 Sensor.TYPE_ORIENTATITON 已被弃用,我不知道如何修复它。是否有可能获得一些帮助。这是我的代码和我所做的。 @Override
到目前为止,我在 Android 设备中发现了以下传感器。我将开发一个应用程序,用于放置有关设备中所有可用传感器的信息。为此,我需要知道除了下面给出的传感器之外,Android 设备还可以拥有多少个传
即使应用程序不在前台,是否可以连续跟踪 Android 上的运动传感器事件? 如果是 - 电池消耗是多少? 一位客户询问是否有可能编写一个应用程序,在人“跌倒”时启动一个 Action ——这基本上意
我正在做一个项目,我需要在计算机上安装一个传感器,如激光传感器或红外传感器,以用于罚球线检测。基本上的想法是,如果有人踩到罚球线,激光或红外线会被人的脚挡住,接收器不会接收到激光/红外线,从而导致传感
我在我的应用程序中应用了 android 传感器框架。它使用 2 个传感器:光和加速度计。传感器已正确注册和注销,应用程序运行正常。该应用程序的 apk 文件大小约为 5 MB,但在安装后,我注意到该
我正在查看 qt 附带的 Qt 传感器的示例应用程序,我已经在 Windows 上编译它没有错误,但是当我尝试将它放到我的 android 上时,我得到了这个编译错误。 10:41:51: Runni
我正在寻找一种解决方案来替代已弃用的 Android 传感器 Sensor.TYPE_ORIENTATION。 报告最多的解决方案是结合Sensor.TYPE_ACCELEROMETER 和Senso
我正在开发将 SensorManager 用于不同目的的 Android 应用程序。在调查过程中,我发现 Sensor.getResolution() 函数为不同的设备返回不同的值: HTC Sens
我正在从 SensorEvent 数据中读取时间戳值,但无法计算出这些值的引用时间。 Android 文档只是说“事件发生的纳秒时间”作为示例: 我当前的 Android 设备日期,2011 年 10
我正在为 Honeycomb Gingerbread 开发,我想知道,当我使用 Sensor.TYPE_ROTATION_VECTOR 时,使用了哪些物理传感器? 它是否结合使用了指南针和加速度计?还
有谁知道 Android 上 Sensor.TYPE_LIGHT 返回值的单位吗? 谢谢。 最佳答案 单位为 SI 勒克斯 (m/s2)。 关于Android Sensor.TYPE_LIGHT 单元
我是一名优秀的程序员,十分优秀!