forked from buba447/simpsonstv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttons.py
35 lines (27 loc) · 787 Bytes
/
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
import RPi.GPIO as GPIO
import time
import os
os.system('raspi-gpio set 19 ip')
GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(18, GPIO.OUT)
def turnOnScreen():
os.system('raspi-gpio set 19 op a5')
GPIO.output(18, GPIO.HIGH)
def turnOffScreen():
os.system('raspi-gpio set 19 ip')
GPIO.output(18, GPIO.LOW)
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)
input = GPIO.input(26)
if input != screen_on:
screen_on = input
if screen_on:
turnOnScreen()
else:
turnOffScreen()
time.sleep(0.3)