-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBacklight.py
More file actions
38 lines (29 loc) · 1.08 KB
/
Backlight.py
File metadata and controls
38 lines (29 loc) · 1.08 KB
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
#=======================================================================
# Copyright Nicholas Tuckett 2015.
# Distributed under the MIT License.
# (See accompanying file license.txt or copy at
# http://opensource.org/licenses/MIT)
#=======================================================================
#!/usr/bin/python
import sys
import os
from os.path import exists
GPIO_ROOT = "/sys/class/gpio"
BACKLIGHT_PATH = GPIO_ROOT + "/gpio252"
class Backlight(object):
def __init__(self):
# Check if GPIO252 has already been set up
if not exists(BACKLIGHT_PATH):
with open(GPIO_ROOT + "/export", "w") as bfile:
bfile.write("252")
# Set the direction
with open(BACKLIGHT_PATH + "/direction", "w") as bfile:
bfile.write("out")
def set(self, light):
'''Turns the PiTFT backlight on or off.
Usage:
Backlight(True) - turns light on
Backlight(False) - turns light off
'''
with open(BACKLIGHT_PATH + "/value", "w") as bfile:
bfile.write("%d" % int(bool(light)))