I am trying to turn on and off the backlight for the 7" official touchscreen using the "echo 1 / 0" commands. When I run the script I get a syntax on the line with the backlight command but I can't see what the issue is. I run the on and off line command in the command prompt and the screen reacts as it should. Below is the code I'm using.
Code: Select all
import RPi.GPIO as GPIO import time import os GPIO.setmode(GPIO.BCM) GPIO.setup(25, GPIO.IN, pull_up_down=GPIO.PUD_UP) shutdownStarted = False while True: if (GPIO.input(25) == False and not shutdownStarted): os.system("sudo shutdown -h -57") echo 1 > /sys/class/backlight/rpi_backlight/bl_power # This stops the code inside this if from being executed again even if the pin stays False shutdownStarted = True secs = 57 * 60 # Run this loop once per second for 57 mins as long as shutdown is still supposed to happen while (secs > 0 and shutdownStarted): if (GPIO.input(25) == True): # This now allows the shutdown -h code to be run again # assuming you want this to execute forever based on the while True you got goin on there shutdownStarted = False os.system("sudo shutdown -c") echo 0 > /sys/class/backlight/rpi_backlight/bl_power time.sleep(1) secs -= 1 time.sleep(1)