- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
实际上,我正在“魔镜”工作,现在我遇到了 python 脚本问题,应该打开/关闭我的显示器。
I copied the python script from this site
#!/usr/bin/env python
import sys
import time
import RPi.GPIO as io
import subprocess
io.setmode(io.BCM)
SHUTOFF_DELAY = 60 # seconds
PIR_PIN = 7 # Pin 26 on the board
def main():
io.setup(PIR_PIN, io.IN)
turned_off = False
last_motion_time = time.time()
while True:
if io.input(PIR_PIN):
last_motion_time = time.time()
sys.stdout.flush()
if turned_off:
turned_off = False
turn_on()
else:
if not turned_off and time.time() > (last_motion_time + SHUTOFF_DELAY):
turned_off = True
turn_off()
time.sleep(.1)
def turn_on():
subprocess.call("sh /home/pi/Documents/PIR/monitor_on.sh", shell=True)
def turn_off():
subprocess.call("sh /home/pi/Documents/PIR/monitor_off.sh", shell=True)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
io.cleanup()
我尝试运行该脚本,但 python 告诉我第 25 行有语法错误,它正好指向 & 之后和 gt 之前的分号
我之前没有使用过python,所以我对python的语法一无所知。
如果你们能花一点时间帮助我解决我的问题,我将非常感激。
我得到了Python版本2.7.9
最佳答案
这不是原始 Python 文件的精确副本。您在复制文件时复制了一些 HTML 标记。
将 >
替换为 >
。
if not turned_off and time.time() > (last_motion_time + SHUTOFF_DELAY):
turned_off = True
turn_off()
您还存在缩进问题和其他应该删除的 HTML 内容:
def main():
io.setup(PIR_PIN, io.IN)
turned_off = False
last_motion_time = time.time()
和
def turn_on():
subprocess.call("sh /home/pi/Documents/PIR/monitor_on.sh", shell=True)
def turn_off():
subprocess.call("sh /home/pi/Documents/PIR/monitor_off.sh", shell=True)
关于python - Raspi 3 PIR 传感器 - Python 脚本 - 语法无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36470387/
我正在尝试检测 PIR 传感器何时触发连续运动超过 8 秒。这是我所拥有的。当传感器处于低电平时,显示“无 Action ...”,然后短 Action 会触发第一个“= 9000UL) {
我需要将“pir 传感器”运动检测 COUNT 写入文本文件。 我尝试使用此代码,无需写入文本文件即可工作。当我写入文件时出现错误 file = open("textFile.txt", "w")In
我们是两个学生,正在从事一个学校项目。任务是将 PIR 传感器(运动传感器)连接到树莓派,每当传感器检测到运动时,它应该向运行 Windows Server 2019 的 AD/DNS 服务器上的文本
我们正在为学校做一个项目,我们有 2 PIR运行在 Arduino 微 Controller 上的运动传感器。我们能够在 Ardunio IDE 和 Python 中查看串行端口的输出 IDLE .
我有一个 PIR 传感器连接到 Amica nodeMCU 板,从 VIN 路由 5v 并通过 USB 端口连接以进行测试。当检测到运动时,它会连接到互联网并将数据发送到 IFTTT,我会在手机上收到
我已经将 NodeMCU 与 Pir 传感器和伺服电机连接起来,代码用于在检测到运动时旋转伺服系统,因此我一旦 void setup() 就将其旋转。这工作正常,但后来在 void loop()它不起
当用户将双手放在 PIR 传感器上时,我无法对 2 个 PIR 传感器的逻辑进行编程以在控制台中打印消息。我已经成功地使用 GPIO、GND 将 PIR 传感器连接到树莓派,并且5v端口。我目前拥有的
我的项目是从 PIR 传感器读取读数,并在人位于传感器前面时播放歌曲,但我无法弄清楚我在网上找到并尝试修改它的这段代码背后的逻辑。 我需要做的是: 如何循环这个,omxp.poll() 不起作用:(
实际上,我正在“魔镜”工作,现在我遇到了 python 脚本问题,应该打开/关闭我的显示器。 I copied the python script from this site #!/usr/bin/
我是一名优秀的程序员,十分优秀!