forked from buba447/simpsonstv
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuttons.py
executable file
·52 lines (40 loc) · 1.18 KB
/
buttons.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python3
import logging
import RPi.GPIO as GPIO
import time
import os
def turnOnScreen():
logging.info("turnOnScreen")
# Enable audio
os.system("raspi-gpio set 19 op a5")
# Turn on screen backlight
GPIO.output(18, GPIO.HIGH)
def turnOffScreen():
logging.info("turnOffScreen")
# Mute audio
os.system("raspi-gpio set 19 ip")
# Turn off screen backlight
GPIO.output(18, GPIO.LOW)
def main():
logging.getLogger().setLevel(logging.INFO)
# Initial GPIO setup
GPIO.setmode(GPIO.BCM)
# Set pin 26 as input to monitor button press
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
# Set pin 18 as output to control screen backlight
GPIO.setup(18, GPIO.OUT)
turnOffScreen()
screen_on = False
while True:
# If you are having and issue with the button doing the opposite of what you want
# IE Turns on when it should be off, change this line to:
# input = not GPIO.input(26)
inp = GPIO.input(26)
if inp != screen_on:
screen_on = inp
if screen_on:
turnOnScreen()
else:
turnOffScreen()
time.sleep(0.3)
main()