Arduinos & Breaduinos
Arduino menu library
Handy menu system for arduino interaction
Input can also be accepted from serial, rotary encoder, joystick, buttons, etc...
Library available from: https://github.com/neu-rah/ArduinoMenu
Arduino menu V2.0
Its an open source library to create menus for the arduino this library is intended to be simple.
Features:
- Associates menu text (prompts) with user defined functions
- Supports sub-menus
- Up-to 16 options per menu (limited by used macros... can be extended by changing the macros)
- Serial menu numbering limited to 9 options per menu, because it executes the options without need of a terminating enter can be extended by using a table (string) that uses letters or by changing the input parser to wait for an enter and parse an integer
- Supports diverse output device types and device sizes LCD and TFT size is user defined (maxX, maxY) in characters (cols and rows)
- Uses any Stream input device.
- Code included for quad-encoder stream and keyboard/button stream
- Can work with multiple input devices at the same time, included code to combine Streams
- Auto inserts an Exit option, defaults to 'false' for base menu
- Exit option is numbered 0
- Exit text can be user defined
- Supports disabled options
- Cursor characters for enabled/disabled cursor is user defined
- Text based, graphical devices should define character size by setting resX, resY
- Menu width can be user defined (usually device size),
- its used to draw selection rectangle on graphocal devices
- Input stream can use characters '+', '-', 'Enter' and 'Escape' to navigate numbers are also valid navigation options
V2.0
main changes:
- non-blocking menu main cycle
- Menufields as menu prompts with associated value
values can be:
numeric withing range
list of values toggled on click (for small lists)
list of values selected as submenu (for longer lists)
- PCINT now supports Mega/2560 and possibly others
notes:
- encoder now needs begin() to be called on setup
- Associates menu text (prompts) with user defined functions
- variable: holding the value (must be numeric or support comparison oprators)
- name: to use as prompt
- units: to be shown after value
- min,max: defining numeric value range
- step: increment/decrement when adjusting value
- tune: increment/decrement when fine tunning the value
- function: called on every value change
- text: to be used as prompt
- value: to be passed when selected
- variable: holding the value
- id: of this element to be used with SUBMENU
- name: to be used as prompt
- variable: holding the value
- id: of this element to be used with SUBMENU
- name: to be used as prompt
- id: the submenu id
- id: this menu id
Simple menu definition (using macros)
menu definition example:
//a submenu
MENU(ledMenu,"LED on pin 13",
OP("LED On",ledOn),
OP("LED Off",ledOff)
);
//field value toggle on click
TOGGLE(targetVar,trigModes,"Mode: ",
VALUE("None",trigPoint::None),
VALUE("On rise",trigPoint::onRise),
VALUE("On fall",trigPoint::onFall),
VALUE("Both",trigPoint::isIn)
);
//field value, click to browse, click to choose
CHOOSE(adc_prescale,sample_clock,"Sample clock",
VALUE("/128",avrADC::clk_128,setADCClk),
VALUE("/64",avrADC::clk_64,setADCClk),
VALUE("/32",avrADC::clk_32,setADCClk),
VALUE("/16",avrADC::clk_16,setADCClk),
VALUE("/8",avrADC::clk_8,setADCClk),
VALUE("/4",avrADC::clk_4,setADCClk),
VALUE("/2",avrADC::clk_2,setADCClk)
);
//the main menu...
//Fields are numeric and show selected value. click to start change, click to fine tune, click to end
MENU(mainMenu,"Main menu",
FIELD(frequency,"Freq","Hz",0,16000000,100,1,updateFreq),
FIELD(dutty,"Duty","%",0,100,1,0,updateDutty),
OP("Handler test",completeHandlerTest),
SUBMENU(trigModes),
SUBMENU(ledMenu)
);
-------------------------------------------------------------------------------
syntax:
OP(name,function)
name: string to be shown as menu option prompt function to be called on click
FIELD(variable,name,units,min,max,step,tune,function)
Holding and changing numeric values
where:
VALUE(text,value)
holding possible FIELD values
where:
TOGGLE(variable,id,name,
VALUE(...),
...,
VALUE(...)
)
Holding a value and a list of possible values to toggle on click
this is ideal for On/Off Yes/No and other small list of values
where:
CHOOSE(variable,id,name,
VALUE(...),
...,
VALUE(...)
)
Holding a value and a list of possible values to select as a submenu
this is ideal for longer lists of values
where:
SUBMENU(id)
link in a submenu as option of the current one
where:
MENU(id,name,
...
OP(...),
FIELD(...),
SUBMENU(...),
...
)
define menu structure
where:
Using an encoder:
//some include files #include "pcint.h"//PCINT, this is incompatible with software serial
#include "quadEncoder.h"//quadrature encoder driver and fake stream #include "keyStream.h"//keyboard driver and fake stream (for the encoder button) #include "chainStream.h"// concatenate multiple input streams (this allows adding a button to the encoder) //the quadEncoder quadEncoder quadEncoder(encA,encB);//simple quad encoder driver, requires PCINT quadEncoderStream enc(quadEncoder,5);// simple quad encoder fake Stream //a keyboard with only one key :D, this is the encoder button //building a tabled associating button pins and retuned character codes //negative pin numbers means we have a pull-up, this is ON when low
keyMap encBtn_map[]={{-encBtn,13}}; keyLook<1> encButton(encBtn_map); //multiple inputs allow conjugation of the quadEncoder with a single key keyboard that is the quadEncoder button Stream* in[]={&enc,&encButton};
chainStream<2> encoder(in); Define menu output to LCD:
#include "menuLCD.h"
menuLCD lcd(lcd1,16,2);//associate menuOut to existing lcd object
Execute the menu using lcd and encoder:
mainMenu.activate(lcd,encoder);//show menu on LCD and use the encoder as input