alle.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import time
  2. import multiprocessing
  3. import Adafruit_BBIO.GPIO as GPIO
  4. import Adafruit_BBIO.PWM as PWM
  5. inPinIR = "P9_12"
  6. inPinPIR = "P9_23"
  7. inPinMAG = "P8_7"
  8. myPWMLAUT = "P8_13"
  9. outPinROT = "P9_27"
  10. GPIO.setup(inPinIR, GPIO.IN)
  11. GPIO.setup(inPinPIR, GPIO.IN)
  12. GPIO.setup(inPinMAG, GPIO.IN)
  13. GPIO.setup(outPinROT, GPIO.OUT)
  14. GPIO.add_event_detect(inPinIR,GPIO.RISING)
  15. GPIO.add_event_detect(inPinPIR,GPIO.RISING)
  16. GPIO.add_event_detect(inPinMAG,GPIO.BOTH)
  17. a=1
  18. try:
  19. time.sleep(2)
  20. while True:
  21. if GPIO.event_detected(inPinIR):
  22. print("Motion detected from IR Sensor...")
  23. for i in range(0,60):
  24. PWM.start(myPWMLAUT, 50, 10000)
  25. GPIO.output(outPinROT,GPIO.HIGH)
  26. time.sleep(0.5)
  27. GPIO.output(outPinROT,GPIO.LOW)
  28. time.sleep(0.5)
  29. PWM.stop(myPWMLAUT)
  30. time.sleep(2)
  31. if GPIO.event_detected(inPinPIR):
  32. print("Motion detected from PIR Sensor...")
  33. for i in range(0,60):
  34. PWM.start(myPWMLAUT, 50, 10000)
  35. GPIO.output(outPinROT,GPIO.HIGH)
  36. time.sleep(0.5)
  37. GPIO.output(outPinROT,GPIO.LOW)
  38. time.sleep(0.5)
  39. PWM.stop(myPWMLAUT)
  40. time.sleep(2)
  41. if GPIO.event_detected(inPinMAG):
  42. if a==0:
  43. print("Fenster ist zu---")
  44. a=1
  45. time.sleep(2)
  46. continue
  47. if a==1:
  48. print("Fenster ist geoeffnet...")
  49. a=0
  50. print("Motion detected from Magnet Sensor...")
  51. for i in range(0,60):
  52. PWM.start(myPWMLAUT, 50, 10000)
  53. GPIO.output(outPinROT,GPIO.HIGH)
  54. time.sleep(0.5)
  55. GPIO.output(outPinROT,GPIO.LOW)
  56. time.sleep(0.5)
  57. PWM.stop(myPWMLAUT)
  58. time.sleep(2)
  59. continue
  60. else:
  61. print("...")
  62. time.sleep(2)
  63. except:
  64. GPIO.cleanup()
  65. PWM.cleanup()