12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- import time
- import multiprocessing
- import Adafruit_BBIO.GPIO as GPIO
- import Adafruit_BBIO.PWM as PWM
- inPinIR = "P9_12"
- inPinPIR = "P9_23"
- inPinMAG = "P8_7"
- myPWMLAUT = "P8_13"
- outPinROT = "P9_27"
- GPIO.setup(inPinIR, GPIO.IN)
- GPIO.setup(inPinPIR, GPIO.IN)
- GPIO.setup(inPinMAG, GPIO.IN)
- GPIO.setup(outPinROT, GPIO.OUT)
- GPIO.add_event_detect(inPinIR,GPIO.RISING)
- GPIO.add_event_detect(inPinPIR,GPIO.RISING)
- GPIO.add_event_detect(inPinMAG,GPIO.BOTH)
- a=1
- try:
- time.sleep(2)
- while True:
- if GPIO.event_detected(inPinIR):
- print("Motion detected from IR Sensor...")
- for i in range(0,60):
- PWM.start(myPWMLAUT, 50, 10000)
- GPIO.output(outPinROT,GPIO.HIGH)
- time.sleep(0.5)
- GPIO.output(outPinROT,GPIO.LOW)
- time.sleep(0.5)
- PWM.stop(myPWMLAUT)
- time.sleep(2)
- if GPIO.event_detected(inPinPIR):
- print("Motion detected from PIR Sensor...")
- for i in range(0,60):
- PWM.start(myPWMLAUT, 50, 10000)
- GPIO.output(outPinROT,GPIO.HIGH)
- time.sleep(0.5)
- GPIO.output(outPinROT,GPIO.LOW)
- time.sleep(0.5)
- PWM.stop(myPWMLAUT)
- time.sleep(2)
- if GPIO.event_detected(inPinMAG):
- if a==0:
- print("Fenster ist zu---")
- a=1
- time.sleep(2)
- continue
- if a==1:
- print("Fenster ist geoeffnet...")
- a=0
- print("Motion detected from Magnet Sensor...")
- for i in range(0,60):
- PWM.start(myPWMLAUT, 50, 10000)
- GPIO.output(outPinROT,GPIO.HIGH)
- time.sleep(0.5)
- GPIO.output(outPinROT,GPIO.LOW)
- time.sleep(0.5)
- PWM.stop(myPWMLAUT)
- time.sleep(2)
- continue
- else:
- print("...")
- time.sleep(2)
- except:
- GPIO.cleanup()
- PWM.cleanup()
|