Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1.  
  2. 5
  3. 6
  4. 7
  5. 8
  6. 9
  7. 10
  8. 11
  9. 12
  10. 13
  11. 14
  12. 15
  13. 16
  14. 17
  15. 18
  16. 19
  17. 20
  18. 21
  19. #!/usr/bin/python
  20. import RPi.GPIO as GPIO
  21. import time
  22.  
  23. #GPIO SETUP
  24. channel = 17
  25. GPIO.setmode(GPIO.BCM)
  26. GPIO.setup(channel, GPIO.IN)
  27.  
  28. def callback(channel):
  29. if GPIO.input(channel):
  30. print "Movement Detected!"
  31. else:
  32. print "Movement Detected!"
  33.  
  34. GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300) # let us know when the pin goes HIGH or LOW
  35. GPIO.add_event_callback(channel, callback) # assign function to GPIO PIN, Run function on change
  36.  
  37. # infinite loop
  38. while True:
  39. time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement