Go Down

Topic: MENWIZ: yet another character lcd menu wizard library (Read 78 times) previous topic - next topic


Apr 03, 2012, 05:00 pm Last Edit: Apr 29, 2014, 10:13 pm by brunialti Reason: 1
EDIT: latest MENWIZ version 1.3.2 beta  is now available on https://github.com/brunialti/MENWIZ_1_3_2
       please sign as follower in order to be notified about new versions!

I had to implement a sketch for sensor management with LCD to set some parameters and to show the mesure in real time.
I abstracted the menu management and i wrote a new library called MENWIZ (menu wizard).

The pros are:
- non blocking: that is the library does not take mu control while working, usefull if your sketch need to work while you are changing the settings
- simple to use (few primitives and compact code)
- user defined splash screen (optional): if you need to show something at startup. The time is user defined.
- user defined callback default screen (optional) activated after a user defined elapsed time since last button push. The menu gently leave the screen to the user, untill any button is pushed.  
- automatic user defined variables binding: that is all parameters changes inside the menus affects also the user defined binded variables
- user defined navigation callback routine (so you can use any navigation device you like, inside the framework)
- actions: callback routines to be executed from menu

- MENWIZ requires LiquidCrystal_I2C and Buttons libraries, enclosed with the package
- I tested MENWIZ mainly with 4x20 I2C lcd screens. It *should* work also with other lcds (e.g 16x2)), but i did'nt testvit extensively
- Menu labels require memory. Be carefull not to run out of  memory (a simple memory-check function is included inthe lib: use it!)

Latest version of MENWIZ:

Any feed back is welcome. Should you be interested I can mantain and expand.
Keep in mind that I want to keep it simple.

The TEST_LIB zip file contains the library used to test the MENWIZ lib.
It should be standard, neverthless should you have some problem, try using it


Please change the title to lowercase, uppercase is considered shouting ...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)



No need to apologize, thank you for "not shouting" ;)

I like new libraries, this is what makes open source great !

Do you have some sample sketches as show case?

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


Apr 03, 2012, 08:49 pm Last Edit: Apr 03, 2012, 09:05 pm by brunialti Reason: 1
Here following the example:

Code: [Select]
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <buttons.h>
#include <MENWIZ.h>

#define UP_BOTTON_PIN       9
#define DOWN_BOTTON_PIN     10
#define LEFT_BOTTON_PIN     7
#define RIGHT_BOTTON_PIN    8
#define ESCAPE_BOTTON_PIN   11

//Create global object LCD and MENU
menwiz menu;
LiquidCrystal_I2C lcd(0x27,20,4);

//instantiate global variables to bind to menu
byte tp=2;
int  gp=26;
boolean wr=0;

void setup(){
 char b[84];
 _menu *r,*s1,*s2;
 _var *v;
 int  mem;

 // have a look on memory before menu creation
 // inizialize the menu object (20 colums x 4 rows LCD)

 //create the menu tree
 r=menu.addMenu(MW_ROOT,NULL,"MAIN MENU");           //create a root menu at first (required)
   s1=menu.addMenu(MW_SUBMENU,r,"MEASURE SUBMENU");   //add a submenu node to the root menu
     s2=menu.addMenu(MW_VAR,s1,"Choose T scale");//add a terminal node in the menu tree (that is "variable");
         s2->addVar(MW_LIST,&tp);                    //create the terminal node variable of type OPTION LIST and bind it to the app variable "tp"
         s2->addItem(MW_LIST,"Celsius");             //add an option to the OPTION LIST
         s2->addItem(MW_LIST,"Farenheit");           //add an other option to the OPTION LIST
         s2->addItem(MW_LIST,"Raw sensor data");     //add the third and last option to the OPTION LIST
     s2=menu.addMenu(MW_VAR,s1,"Set T1 trigger");
     s2=menu.addMenu(MW_VAR,s1,"Enable warmer");

 //(optional) create a splash screen (lap 6 seconds) with some usefull infos
 //the character # marks end of line
 //(tip): use preallocated internal menu.sbuf buffer to save memory space!
 sprintf(menu.sbuf,"MENWIZ TEST V %s#Free memory   : %d#Menu mem alloc: %d#Splash lap sec: %d",menu.getVer(),menu.freeRam(),mem-menu.freeRam(),6);
 menu.addSplash((char *) menu.sbuf, 6000);

 //declare navigation buttons (required)
 // equivalent shorter call: menu.navButtons(9,10,7,8,11,12);
 // create a user define screen callback to activate after 7 secs since last button push

void loop(){

// user defined default screen
void msc(){
 lcd.print("                    ");
 lcd.print("Test user screen");
 lcd.print(millis()/1000);  lcd.print("        ");
 lcd.print("                    ");

Go Up