I want to create a script that will turn off my Raspberry Pi Touchscreen if nobody touched the screen in 30 seconds. (In the future I want the option to reset this 30 second timer with other programs - i.e REST API).
This is what I currently have
from pynput import mouse import time import rpi_backlight as bl bl.set_power(False) # Turn Off the Screen Initially def on_move(x, y): control_screen() def on_click(x, y, button, pressed): control_screen() def control_screen(): if (bl.get_power() == False): # If the Screen is OFF bl.set_power(True) # Turn On Screen bl.set_brightness(200, smooth=True, duration=3) time.sleep(30) # Wait 30 Seconds bl.set_power(False) # Turn Screen Off Again # Collect events until released with mouse.Listener( on_move=on_move, on_click=on_click) as listener: listener.join()
The problem with this code is that the screen sleeps and then immediately wakes up again (maybe the on_click/on_move are triggered when this occurs)? And also I don't think the sleep(30) is the best approach as I want the sleep timer to start over once the screen is touched. Any tips?