Science Oxford Logo

Understanding and editing the Pushbutton code


How does the current code work?

The button has three functions:


In the code, starting around line 37, the first two types of press are being used, but the long press currently does nothing.

For each type, doing the press toggles between showing something on the screen and showing the data you have chosen to display.


The structure of the working buttons is:

async def wait_press(e, lcd):
  global data
  while True:
    await e.wait()
    e.clear()
    print("Debugging: button pressed")
        
    if data == True:
      # do something
      data = False

    else:
      lcd[0] = ""
      lcd[1] = ""
      data = True

Breaking this down:

Set up

Editable

Edit the Long Press

The code feels complicated, but what you are doing is either displaying the data set up further down in your code, or displaying something else.

To start with, leave button press and double press alone, as they do useful things, and edit the long press code only.

  1. Find the 'long press' function - this will be around line 86.
  2. The set up code is already there, do not change this.
  3. Add the code shown above, (if data = True: else:).
  4. What do you want to show on the LCD screen when you long press the button? A message? Some other data?

If you are confident editing the button presses, you can also change the behaviour of the other two.