I was wondering if there are a way to do a menu system for arduino UNO using buttons and without libraries.
I tried to do it by myself but the code was too long and heavy.
I don't want full code, just a pseudo-code idea and how does it works.
I know there are libraries that to this, but I want to practise C++.
Thanks!
1 Answer 1
Interactive menus are certainly not a "simple" task. That is why people use libraries.
Whatever you try you will end up with complex code - either long winded with lots of duplication, or somewhat cryptic with lots of pointers, arrays, and structures. Not an easy task for a beginner in C++.
How I would set about it would involve the following things:
- A structure that defines a menu entry, including pointers to one of: sub-menu array, numeric variable (including max/min limits), option array, function to execute.
- Arrays of the above structure to define each menu
- Array or linked list of "breadcrumbs" through the menu to track where you are and go back up properly
- Functions to display and navigate the menu arrays on an LCD.
All of that uses fairly advanced C coding techniques, especially when it comes to managing all the pointers, etc.
The "simpler", though more long winded way, would be to write individual functions for each menu and sub-menu, but that would make your program incredibly long and prone to have errors when duplicating (copy/paste) code.
-
agree, i would add that all those structures probably will end up taking a lot of ram.. and sooner or later you will end up wanting them on flash memory, bringing even more complexity to your code, but yes, go for it! its a good chance to later appreciate a library and still learn a lot of c++ :Dneu-rah– neu-rah2017年03月03日 19:37:00 +00:00Commented Mar 3, 2017 at 19:37