User avatar
rhe8502
Posts: 3
Joined: Tue Sep 10, 2019 9:39 pm
Location: Ireland
Contact: Twitter

Displayotron 3000 - toggle backlight on/off with joystick

Tue Sep 10, 2019 10:00 pm

Hi,

I'm wondering if there is a way to check the backlight status on a Pimoroni DisplayOtron 3000 (e.g., if the backlight is currently on, or off), so that when I push the joystick button the backlight is either toggled on or off.

I tried to do the following, but it doesn't work.

Code: Select all

# Set Joystick options
@nav.on(nav.BUTTON)
def handle_button(pin):
    if backlight.off():
         backlight.rgb(50, 255, 50)
    else:
        backlight.off()

The only way I managed to accomplish this is if I introduce a variable called "status" and change to either True or False. It works, but it doesn't seem to be an elegant solution.

Code: Select all

# Set Joystick options
@nav.on(nav.BUTTON)
def handle_button(pin):
    global status
    if status:
        backlight.off()
        status=False
    else:
        backlight.rgb(50, 255, 50)
        status=True

pcmanbob
Posts: 6618
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Displayotron 3000 - toggle backlight on/off with joystick

Wed Sep 11, 2019 10:36 am

Hi.

You might get an answer if you ask on Pimoroni's support forum, after all its their product.

https://forums.pimoroni.com/c/support
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

scotty101
Posts: 3670
Joined: Fri Jun 08, 2012 6:03 pm

Re: Displayotron 3000 - toggle backlight on/off with joystick

Wed Sep 11, 2019 11:08 am

The problem is that the code library for the displayotron, does not allow you to read the current status of the backlight.

The line

Code: Select all

if backlight.off():
Will turn the LED off and execute the code inside the if branch if backlight.off() returns true but the off function doesn't return anything so the if branch will never execute.

The solution you've come up with is probably what you are stuck with unless you modify the code library to keep track of what the status of the backlight is.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

User avatar
rhe8502
Posts: 3
Joined: Tue Sep 10, 2019 9:39 pm
Location: Ireland
Contact: Twitter

Re: Displayotron 3000 - toggle backlight on/off with joystick

Wed Sep 11, 2019 11:59 am

pcmanbob wrote:
Wed Sep 11, 2019 10:36 am
Hi.

You might get an answer if you ask on Pimoroni's support forum, after all its their product.

https://forums.pimoroni.com/c/support

Thanks pcmanbob. I did post it on the Pimoroni support forum as well, but haven't received any feedback on it yet.
https://forums.pimoroni.com/t/displayot ... tick/11597

User avatar
rhe8502
Posts: 3
Joined: Tue Sep 10, 2019 9:39 pm
Location: Ireland
Contact: Twitter

Re: Displayotron 3000 - toggle backlight on/off with joystick

Wed Sep 11, 2019 12:05 pm

scotty101 wrote:
Wed Sep 11, 2019 11:08 am
The problem is that the code library for the displayotron, does not allow you to read the current status of the backlight.

The line

Code: Select all

if backlight.off():
Will turn the LED off and execute the code inside the if branch if backlight.off() returns true but the off function doesn't return anything so the if branch will never execute.

The solution you've come up with is probably what you are stuck with unless you modify the code library to keep track of what the status of the backlight is.

Thanks scotty101. Yes, that's what I was trying to find out. Would be nice to be able to query the status. Not the end of the world though, the workaround works well enough for my simple use case.

Will have a look at the code library later as well.

Return to “HATs and other add-ons”