Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
input_state = GPIO.input(18)
if input_state ==False:
if open('tmp').readline().rstrip() == "0":
os.system("sudo bash -c 'echo 1 > /sys/class/backlight/rpi_backlight/bl_power'")
os.system("echo 1 > tmp")
else:
os.system("sudo bash -c 'echo 0 > /sys/class/backlight/rpi_backlight/bl_power'")
os.system("echo 0 > tmp")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment