2016-04-07 14 views
1

Aslında bir "Sihirli Aynada" çalışıyorum ve şimdi monitörümü açıp/kapatmam gereken python betiğiyle ilgili bir sorunum var. Raspi 3 PIR sensörü - Python betiği - geçersiz sözdizimi

#!/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() 

I copied the python script from this site

Ben komut dosyasını çalıştırmak çalıştı, ancak piton hattı 25 bir sözdizimi hatası var söyle, bu & amp sonra ve gt

önce noktalı virgül tam olarak işaret

Şimdiye kadar python ile çalışmadım, bu yüzden pythonun sözdizimi hakkında hiçbir şey bilmiyorum.

Sorunumu çözmemde bana yardımcı olacak bir dakika alacak olursanız çok memnun olurum.

Ben Bu orijinal Python dosyasının tam kopyası değil piton sürüm 2.7.9

cevap

2

aldık. Dosyayı kopyalarken bazı HTML işaretlerini kopyaladınız.

>'u > ile değiştirin.

if not turned_off and time.time() > (last_motion_time + SHUTOFF_DELAY): 
     turned_off = True 
     turn_off() 

Ayrıca kurtulmak gerektiğini girinti konuları ve diğer HTML şeyler var: Hey çok teşekkür ederim

def main(): 
    io.setup(PIR_PIN, io.IN) 
    turned_off = False 
    last_motion_time = time.time() 

ve

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) 
+0

!! Bu bir çekicilik xD gibi çalışır ... Geçmişte daha önce böyle bir sorun vardı, ama ben hatırlamadım. – prototype0815