Been struggling with this for a while. I’d like the backlight of the DisplayoTron to come on in response to any button press and then switch off again say 30 seconds after the last input. I’m aware of the methods for turning on and off the backlight but I’m struggling to understand how I could achieve this without having to totally re-write the menu standard menu class.
Hmm- I recall that the Menu system has a screensaver feature already built in which could call a plugin that turns off the backlight when it’s run, and turns it back on again when it’s cleaned up.
Every button action in the Menu will check the idle status and call cleanup() on the idle_handler plugin when a button is pressed:
So a plugin that just does this set as the idle_handler may also work:
import dothat.backlight as backlight
import dothat.lcd as lcd
import dothat.touch as nav
class IdleBacklight(MenuOption):
def __init__(self, backlight):
self.backlight = backlight
MenuOption.__init__(self)
def cancel(self):
self.backlight.rgb(255, 255, 255)
def begin(self):
self.backlight.rgb(0, 0, 0)
menu = Menu(
structure=... blah blah,
lcd=lcd,
idle_handler=IdleBacklight(backlight),
idle_timeout=3
)
nav.bind_defaults(menu)
while 1:
menu.redraw()
time.sleep(0.05)
Note: my example differs slightly from the above solution since I ran into a couple of quirks and improved it to use the backlight setting set by the Backlight config plugin
Thanks chaps! I’ll take a look at this and see if I can get it going and report back.
For ages I wanted to get some code working which controls my Phillips Hue lighting and integrates with the DisplayOTron, I’ve got it all working now and am just tinkering to try and improve the system and add a stack of features.