1234567891011121314151617181920212223242526272829303132333435363738 |
- import time
- import Adafruit_BBIO.GPIO as GPIO
- GPIO.setup("P9_15",GPIO.OUT)
- inPin = "P8_7"
- GPIO.setup(inPin, GPIO.IN)
- GPIO.add_event_detect(inPin,GPIO.BOTH)
- a=1
- try:
- time.sleep(2)
- while True:
- if GPIO.event_detected(inPin):
- #GPIO.output("P9_15",GPIO.HIGH)
- #time.sleep(0.5)
- #GPIO.output("P9_15",GPIO.LOW)
- if a==0:
- print("Fenster ist zu---")
- a=1
- time.sleep(1)
- continue
- if a==1:
- print("Fenster ist geoeffnet...")
- GPIO.output("P9_15",GPIO.HIGH)
- time.sleep(0.5)
- GPIO.output("P9_15",GPIO.LOW)
- a=0
- #print("Motion detected...")
- time.sleep(1)
- continue
- else:
- print("...")
- print(a)
- time.sleep(1)
- except:
- GPIO.cleanup()
|