Advertisement
Guest User

Untitled

a guest
Jun 27th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import time
  3. from threading import Timer
  4. import subprocess
  5.  
  6.  
  7. GPIO.setmode(GPIO.BCM)
  8. GPIO.setup(11, GPIO.IN)
  9. timer = False
  10. monitor_is_on = True
  11.  
  12. def monitor_off():
  13. global monitor_is_on
  14. subprocess.call(['/opt/vc/bin/tvservice', '-o'])
  15. monitor_is_on = False
  16.  
  17. def monitor_on():
  18. global monitor_is_on
  19. subprocess.call(['/opt/vc/bin/tvservice', '-p'])
  20. subprocess.call(['fbset -depth 8'], shell=True)
  21. subprocess.call(['fbset -depth 16'], shell=True)
  22. subprocess.call(['xrefresh'], shell=True)
  23. monitor_is_on = True
  24.  
  25.  
  26. while True:
  27. time.sleep(0.5)
  28. movement = GPIO.input(11)
  29. if movement:
  30. if timer:
  31. print "canceler timer"
  32. timer.cancel()
  33. timer = False
  34. if not monitor_is_on:
  35. print "Taender skaerm"
  36. monitor_on()
  37. else:
  38. if not timer:
  39. print "starter timer"
  40. timer = Timer(60*5, monitor_off)
  41. timer.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement