Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import time, sys
- import RPi.GPIO as GPIO
- import os
- # Steckplatz am Raspberry
- PIR = 22
- # Initialisierung
- def initPIR(PIR):
- print "Warte aus PIR..."
- while GPIO.input(PIR) == 1:
- print "Bereit!"
- return 0
- # Was passiert bei Bewegung
- def motion_on():
- print "Bewegung erkannt um"
- print(time.strftime("%d.%m.%Y %H:%M:%S"))
- os.system('vcgencmd display_power 1')
- time.sleep(300)
- return
- # Was passiert wenn nach der Wartezeit keine Bewegung mehr wahrgenommen wird
- def motion_off():
- print "Keine Bewegung seit"
- print(time.strftime("%d.%m.%Y %H:%M:%S"))
- os.system('vcgencmd display_power 0')
- return
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(PIR, GPIO.IN)
- PirPreviousState = 0
- PirCurrentState = initPIR(PIR)
- try:
- while True:
- PirCurrentState = GPIO.input(PIR)
- if PirCurrentState == 1 and PirPreviousState == 0:
- motion_on()
- PirPreviousState=1
- elif PirCurrentState == 0 and PirPreviousState == 1:
- motion_off()
- PirPreviousState=0
- time.sleep(.1)
- except KeyboardInterrupt:
- GPIO.cleanup()
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement