Framework for device(functions)

Hi fellow Arduino-ers,

For a project I am doing, I am making a device that has a screen, some buttons, some sensors, and a battery. The PCB is finally done, and runs a ATmega4809 as a MCU (same as in a Arduino Nano Every), so now it's "officially" time for the software. But before I start randomly Programming, I want a good idea on how to tackle this.

The main function of the device is something that I have a good idea about writing, IF I could just build that in the main-loop, and not have the device do anything else.

The part that I don't know so well about is how to make a good framework for the device so that the user can interact with it: alter some settings, scroll through different menus, turn on the backlight, and of course put the device in "active" mode. I have thought about how to do this, and I came up with some ideas. But I am wondering if there is any sort of "best practice" way to do this, or even if there are some libraries that I can use.

The method that comes to mind for me is using a finite state machine system (e.g. with this library: GitHub - jrullan/StateMachine: State machine library for Arduino ), where the device can be in a couple different states, depending on which menu or mode you are in, and switch states on user interaction. In every state I would write some sort of loop, which will contain whatever the device must do in that state.

Do any of you have any other good ideas, or tips on what I should watch out for?

Thanks

A state machine sounds good, but there's no need to loop in each state. Let loop do the looping and call the state machine's controller function from there.

I know nothing about that library but I would advise you to avoid it simply because if you come here looking for help, you may limit your pool of advisors to those folks (if any) who have used it.

You may also get some ideas from these links
Planning and Implementing a Program
Several Things at a Time

Note how each function runs very briefly and returns to loop() so the next one can be called. None of the functions tries to complete a task in one call. And there may be dozens of calls to a function before it is actually time for it to do anything.

...R