Returning LCD keypress

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
noven
 
Posts: 6
Joined: Tue Oct 08, 2013 6:49 pm

Returning LCD keypress

Post by noven »

I'm working on some code to cycle through functions on the LCD using buttons. This works perfectly for simple one line commands. But when I need to call another function I wish one keypress to exit the loop AND pass that same keypress back to the menu function to cycle.
Snippet:

Code: Select all

def pident():
    while True:
        hostname = subprocess.check_output("hostname")
        hostip = subprocess.check_output("ip addr show eth0 | grep 'inet ' | awk '{ print $2}'", shell=True)
        lcd.backlight(lcd.WHITE)
        lcd.clear()
        lcd.message("Pi %s \n" % hostname)
        lcd.message(hostip)
        sleep(0.5)
        if (lcd.buttonPressed(lcd.UP) | lcd.buttonPressed(lcd.DOWN) | lcd.buttonPressed(lcd.LEFT) | lcd.buttonPressed(lcd.RIGHT)):
            return lcd.buttonPressed
The function does it's job until a key is pressed. Then it exits the loop but doesn't pass the button press back to the menu - I have to press it a second time and it works. Is there a simple change to the final return statement that could pass the result back? Or should I look at reengeneering the code?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Returning LCD keypress

Post by adafruit_support_rick »

You can return lcd.buttons(). That will give you a bitmap of the currently pressed buttons.

noven
 
Posts: 6
Joined: Tue Oct 08, 2013 6:49 pm

Re: Returning LCD keypress

Post by noven »

Excellent and easy, thankyou :)

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”