IR_01.py 693 B

1234567891011121314151617181920212223242526272829
  1. import time
  2. import Adafruit_BBIO.GPIO as GPIO
  3. GPIO.setup("P9_15",GPIO.OUT)
  4. inPin = "P9_12"
  5. GPIO.setup(inPin, GPIO.IN)
  6. GPIO.add_event_detect(inPin,GPIO.RISING)
  7. try:
  8. time.sleep(2)
  9. while True:
  10. if GPIO.event_detected("P9_12"):
  11. GPIO.output("P9_15",GPIO.HIGH)
  12. time.sleep(0.5)
  13. GPIO.output("P9_15",GPIO.LOW)
  14. print("Motion detected...")
  15. time.sleep(3)
  16. else:
  17. print("---")
  18. GPIO.output("P9_15",GPIO.LOW)
  19. #sleep(0.5)
  20. #GPIO.output("P9_15",GPIO.LOW)
  21. #sleep(0.5)
  22. #GPIO.output("P9_15",GPIO.HIGH)
  23. #sleep(0.5)
  24. #GPIO.output("P9_15",GPIO.LOW)
  25. time.sleep(2)
  26. except:
  27. GPIO.cleanup()