Rotary controller OLED menu updated
Many moons ago (well, size years – approximately 71 full moons), I put a little python code up on GitHub to show a menu on a 128×32 pixel OLED screen and allow changing the highlighted option with a rotary controller (potentiometer).
I had intended to create some kind of clock radio alarm with a raspberry pi, but never swung back to that project as I just use my phone (like most people would), so that code never got touched after the initial commit.
Yesterday I decided the code needed a little love (and because the bread board with the OLED screen and rotary controller was still on my desk taunting me!)
New things
The updated code has had a little restructure and added some new things:
- New way of creating menus
It’s not just a simpledict
any longer, but instead the menu needs to be constructed using theMenuAction
orMenuParent
classes. - Menu options can now perform actions
Using theMenuAction
class, when you use the rotary controller’s push/button action, it can now perform the action of that menu option, be it a lambda or a class function, or whatever callable type you want to use. - Menus can be multi-level
Using theMenuParent
allows you to group together sub-actions, and allow you to navigate to that level of menu on the rotary push action. There’s also a back option automatically added for any parent.
Demo
Here’s an example video of it in action. How to set it up (what pins to use on the raspberry pi and what the code looks like) can all be found on the project’s repo on GitHub.