Skip to content
Advertisement

Two-Button Menu Iteration

I’ve got a script that I’m adapting to micropython on a 2040, and I want to use two buttons to navigate the menu structure. I can’t figure out how to make the iterate loop in the multi-choice menus work right… here’s what I’ve got so far:

JavaScript

In particular, this is the logic I’m wrangling with:

JavaScript

Here’s what I’m wanting to do:

For each item in the set,

  • Display the item, wait for button press
  • If button 1 is pressed, select that item, return the item.
  • If button 2 is pressed, display the next item, wait for button press.
  • (iterate until button 1 pressed to select item)

Again, this is micropython, so I don’t have all the modules you’d think available… woudl be best to do this in raw code.

Advertisement

Answer

0.01 second is way too short. The key is, after you detect “button down”, you need to wait for “button up”. You need something like:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement