For this example we will create a menu that has two top level menu items; a counter which counts down from the selected value, and a Boolean switch that turns on or off the countdown. It will also have a submenu with one menu item to control the notification method. So lets draw this out conceptually below
menu root
+- countdown, integer values 0 to 1000 seconds
+- enabled, boolean YES, NO.
+- settings (sub menu)
+- alert (one of SOUND, LIGHT, BOTH)
Create a new Arduino project in your sketches area, start a new project in the TcMenu editor and save it into the
new Arduino project directory. It will create an EMF
file with the chosen name in that directory.
Ensure Root is selected in the tree and press the + button from the toolbar (2). We want a numeric item so choose
“Analog Item” as the type. Once you press ok a new menu item should be created and selected in the tree.
In the editor area (4) change:
We are now ready to create the second item. Again press the + button from the toolbar (2) to create a second item, this time choose BooleanMenuItem as the type and press create. In the editor area (4):
Now, we create the submenu by choosing the + button again, this time choose Sub menu as the type and press create. Change the name to Settings and leave all other fields as is.
Ensuring the newly created submenu is selected, press the + button again, this time choose Enumeration item and press create. In the editor area:
At this point we have finished creating the menu, we now move on to generating code.
When generating eeprom values, note that values 0 and 1 are reserved for a “magic key”. This is so that load knows if the eeprom is still intact at startup. If you need to change the magic key it’s defined in the tcMenu headers.
Before generating code, it is advisable to check the ID and eeprom ranges, to ensure there are no overlaps. To do this, from the Code menu choose “Show ID and Rom Layout”; which will pop up the following dialog:
On the left you see the IDs laid out in numeric order, and on the right the rom layout. If there are any overlaps in the rom, I.E. a value that overlaps with another, it is highlighted in red. Any overlaps should be changed before generating code.
Finally, we get to generating the code for Arduino. Choose Code/Generate Code from the menu. You should see a dialog similar to the following:
Once this dialog appears you’ll notice it’s split into roughly two areas, the platform and hardware choices, and the properties that need to be defined for those choices.
Once all the above choices are set, you need to define the parameters that will be used by these plugins. In order to do this, you need to fill in the properties table (lower part of dialog) with your values. Notice each row in the list has a description along with the variable name, so you know what it’s for. These values will be saved into your project file (don’t forget to press save after leaving the generator)!
Press the generate button, a new window should popup, that logs the code generation run. Once complete the menu files and the sketch should be generated. At this point, as long as all the properties were defined above, and the circuit is built, you should have a functioning menu to build in your favorite IDE!
Hope you enjoy using TcMenu!