事实上,我是在一个“魔镜”工作,现在我遇到了一个问题,因为python脚本应该打开/关闭我的显示器。
#!/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的语法一无所知。
如果你们能花点时间帮我解决我的问题,我将非常感激。
我得到了pythonVersion2.7.9
发布于 2016-04-07 08:17:45
这不是原始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)https://stackoverflow.com/questions/36470387
复制相似问题