I just finished assembling and testing this beauty...
I would like to use a timeout of 10 seconds for its screen backlight.
The final result I have in mind would be:
if screen is off and user press any button turn it on, wait 10 seconds and turn it off again.
if screen is already on kill current counter and count 10 seconds again before turning the screen off.
I tried this but it works horribly and it uses a global variable which is, again, horrible.
Code: Select all
def turn_backlight_off():
lcd.set_backlight(0.0)
def turn_backlight_on():
global timer_backlight
if timer_backlight:
timer_backlight.cancel()
timer_backlight = threading.Timer(10.0, turn_backlight_off).start()
else:
lcd.set_backlight(0.1)
timer_backlight = threading.Timer(10.0, turn_backlight_off).start()
Any hint to tackle this problem?