Ah, thank you. I'll try that again:
Code:
import RPi.GPIO as GPIOimport subprocessimport time# Set up GPIO using BCM numberingGPIO.setmode(GPIO.BCM)# Set up GPIO pin for the switchswitch_pin = 17GPIO.setup(switch_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)# Main looptry: while True: # Check the state of the switch if GPIO.input(switch_pin) == GPIO.LOW: # Switch is off, turn off the display subprocess.run(['vcgencmd', 'display_power', '0']) else: # Switch is on, turn on the display subprocess.run(['vcgencmd', 'display_power', '1']) # Delay for a short time to avoid high CPU usage time.sleep(0.1)except KeyboardInterrupt: GPIO.cleanup()
Statistics: Posted by ike-g — Mon Apr 01, 2024 1:09 pm