Magnet_01.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import time
  2. import Adafruit_BBIO.GPIO as GPIO
  3. GPIO.setup("P9_15",GPIO.OUT)
  4. inPin = "P8_7"
  5. GPIO.setup(inPin, GPIO.IN)
  6. GPIO.add_event_detect(inPin,GPIO.BOTH)
  7. a=1
  8. try:
  9. time.sleep(2)
  10. while True:
  11. if GPIO.event_detected(inPin):
  12. #GPIO.output("P9_15",GPIO.HIGH)
  13. #time.sleep(0.5)
  14. #GPIO.output("P9_15",GPIO.LOW)
  15. if a==0:
  16. print("Fenster ist zu---")
  17. a=1
  18. time.sleep(1)
  19. continue
  20. if a==1:
  21. print("Fenster ist geoeffnet...")
  22. GPIO.output("P9_15",GPIO.HIGH)
  23. time.sleep(0.5)
  24. GPIO.output("P9_15",GPIO.LOW)
  25. a=0
  26. #print("Motion detected...")
  27. time.sleep(1)
  28. continue
  29. else:
  30. print("...")
  31. print(a)
  32. time.sleep(1)
  33. except:
  34. GPIO.cleanup()