Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- import time
- from threading import Timer
- import subprocess
- GPIO.setmode(GPIO.BCM)
- GPIO.setup(11, GPIO.IN)
- timer = False
- monitor_is_on = True
- def monitor_off():
- global monitor_is_on
- subprocess.call(['/opt/vc/bin/tvservice', '-o'])
- monitor_is_on = False
- def monitor_on():
- global monitor_is_on
- subprocess.call(['/opt/vc/bin/tvservice', '-p'])
- subprocess.call(['fbset -depth 8'], shell=True)
- subprocess.call(['fbset -depth 16'], shell=True)
- subprocess.call(['xrefresh'], shell=True)
- monitor_is_on = True
- while True:
- time.sleep(0.5)
- movement = GPIO.input(11)
- if movement:
- if timer:
- print "canceler timer"
- timer.cancel()
- timer = False
- if not monitor_is_on:
- print "Taender skaerm"
- monitor_on()
- else:
- if not timer:
- print "starter timer"
- timer = Timer(60*5, monitor_off)
- timer.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement