MENWIZ: yet another character lcd menu wizard library

Hi Guys
I first time run the Menwiz with the Terry sketch and i confess i never saw any menu library that good and easy of use. I am using 3-wire LCD and AnalogeButton.

I shall soon post the results with Video. I am really very happy.
Thank you brunialti for the great MenWiz
Thank you backbone for Analoge Button Sketch
Thank You **Terry ** for the good sketch of your controller
Thank You rest for their great contributions in library and all the help you providing.

Hi brunialti ,
I have a question. If we have a function having conditional WHILE loop or FOR loop inside void loop(). Then what will happen to navigate buttons and menu.draw function? Will it work or not i.e. screen will display the menu? Will the menu recognize the button press?
For example:

void loop()     
{
  while(READ_RIGHT_LDR >= lightPoint || darknessDuration < (6*60*60*1000)) //While it's light outside or has been dark for less than 6 hours.CHECK RIGHT SENSOR
  {
    if (READ_RIGHT_LDR >= lightPoint) //If it's light outside
    {
      updatePosition();
      darknessDuration = 0;
    }
    delay(1*10*1000); //Wait 10 sec before checking again.THIS DELAY HAS TO BE CONTROLLED WITH A VARIABLE IN MENU
  }
  menu.draw();
  readButtons();
}


void updatePosition()
{
  int rightSide, leftSide, noChangeCount = 0;
  while (noChangeCount < 5)
  {
    checkHaltSwitches();
    rightSide = READ_RIGHT_LDR;
    leftSide = READ_LEFT_LDR;

    if (leftSide + Sensitivity < rightSide && !moveRightHalted)
    {
      LED_LEFT_OFF;
      MOTOR_OFF;
      delay(50);
      LED_RIGHT_ON;
      MOTOR_RIGHT;
      MOTOR_ON;
#if defined(DEBUG)
      Serial.print("Move Right: ");
#endif
    }
    else if (leftSide > rightSide + Sensitivity && !moveLeftHalted)
    {
      LED_RIGHT_OFF;
      MOTOR_OFF;
      delay(50);
      LED_LEFT_ON;
      MOTOR_LEFT;
      MOTOR_ON;
#if defined(DEBUG)
      Serial.print("Move Left:  ");
#endif
    }
    else
    {
      LED_LEFT_OFF;
      LED_RIGHT_OFF;
      MOTOR_OFF;
#if defined(DEBUG)
      Serial.print("-Centered-: ");
#endif
      noChangeCount++;
      delay(1000);
    }
#if defined(DEBUG)
    Serial.print("leftSide: ");
    Serial.print(leftSide);
    Serial.print(", rightSide: ");
    Serial.println(rightSide);
#endif
    delay(100);
  }
  LED_LEFT_OFF;
  LED_RIGHT_OFF;
  MOTOR_OFF;
#if defined(DEBUG)
  Serial.println("Position updated.");
#endif

  return;
}

MENWIZ has not its own scheduler. So anything happens at .draw() calltime.
If you make a loop before calling .draw() method (or execute a long lasting code), button checking and any other MENWIZ methods will be delayed until next .draw call.

By the way i'm going to deliver a new version of MENWIZ with some rendering improvement (so called "collapsed menus"). Tests are wellcome !

Sure, we are here to test and thank you for improvement in your library. Any way or suggestion how can i write the above piece of code so that MENWIZ can work? any pseudocode?

something like the following (not tested nor compiled, just for example):

long startdarkness=0, lastread=0;
void setup(){
}

void loop(){

if ((millis()-lastread)>10000)){   // first read after 10 secs since start
  if (checkligth() {   // ligth outside
      startdarkness=0; 
      lastread=millis(); // store last check time
     }
  else{ //dark outside
     if(stardarkness==0)        // no darkness in previous check
        startdarkness=millis();      
     }
}
if( (millis()-startdarknes)< LAPTIME){
//... DO YOUR STUFF....
  }
menu.draw();
}

byte checkligth(){

// this function must return 0 if dark, 1 otherwise

}

by the way what is readbuttons()?

Hi guys!
I need test volunteers for the 1.1.0 version here attached before github publishing.
This version introduces the following improvements:

  • smaller footprint. About 1.6 Kb less of progmem (and few tens of bytes of heap). As the library does not use anymore sprintf function, in order to save the above mentioned memory amount, the user code need to avoid sprintf as well
  • implementation of the "collapsed menu" rendering. This behaviour is available only in the 6 buttons mode (as I could not find an interaction model for the 4 buttons mode...)

Please test at first with existing code, in order to be sure i did'nt introduce regressive errors.
After test the new behaviour

Thanks!

TEST MENWIZ 1-1-0.zip (156 KB)

brunialti:
something like the following (not tested nor compiled, just for example):

by the way what is readbuttons()?

That is some brilliant piece of code i was looking for:) Thank you very much... The readbuttons() is a custom function for reading a state of button using analogpin of arduino and it is working very well here:)
I will test today the collapse menu new features of MENWIZ and let you tell the results.
Thank you again.
Regards

I am getting following error when i loaded the example with just adding the custom button function. My sketch is also attached.

Test_all_var_types_new2.ino (9.14 KB)

addUsrNav has now two parameters. The first one is the callback function expected to give back the button code, the other one is the number of buttons emulated by the call back function declared as first parameter (allowed values: 6 or 4).
You do not need anymore to set the internal variable MW_navbtn (you can delete following code line in the sketch!)
in your case the correct call is:

menu.addUsrNav(navMenu,6);

I need to explicitly describe the syntax in the manual....

Okay, Now its running fine and i can enter into submenu "MEASURE SUBMENU" as i am using only 4 buttons (CONFIRM, ESCAPE, UP and DOWN) so i am unable to change the Variable parameters. I think the LEFT and RIGHT buttons are intended to do the same. As i have the six button but two buttons are not implemented so unable but soon i will update the code of all six buttons and will let you tell.
The menu by the way is working very good and i really like the collapsing feature. It will save a lot of space on the screen and organizing the program.
Keep in mind i am using custom function for controlling the six keys keypad that is driven by one Analogue pin of Arduino.
Brilliant:)
Whats coming up next:)
Now how to store an integer value in EEPROM? you have given loadvar and savevar functions but can you define how we put the integer value (2 bytes) in EEPROM address say 0 and 1.

void savevar(){
  menu.writeEeprom();
  }
  
void loadvar(){
  menu.readEeprom();
  }

Regards

The EEPROM save/load functions apply only to the MENWIZ variables.
The save function stores the variable in FIFO mode (first to be declared, first to be saved). So in theory the first defined variable should be stored in the first 2 bytes of EEPROM space.

brunialti:
The EEPROM save/load functions apply only to the MENWIZ variables.
The save function stores the variable in FIFO mode (first to be declared, first to be saved). So in theory the first defined variable should be stored in the first 2 bytes of EEPROM space.

You are Genius ..This means i have no worries about storing the variables (int, float etc) in EEPROM. Your MENWIZ is taking care of it by storing and retrieving the variables info :slight_smile:
I also think that once program/sketch burns in the Arduino. The location of variables in the EEPROM will be always same. Suppose the first variable stored in 0 and 1 address of EEPROM. It will always store and retrieve from the same address throughout the life of the program.

I really like the ease of your library. Thank you for all of your hardwork.
What are your future plans :slight_smile:
Regards

Yes. You have not to take care about allocation. It is a MENWIZ duty ....
All variables are stored/loaded togheter with one function call.

All is in the example.

brunialti:
Yes. You have not to take care about allocation. It is a MENWIZ duty ....
All variables are stored/loaded togheter with one function call.

All is in the example.

Thats Cool features .. Your programming is unbelievable..Just saw the MENWIZ.cpp and Header file and your programming skills are at par excellence.

Hi,
I implemented the Left and Right button in the sketch. But in your new COLLAPSE MENU i think the Left and Right buttons are not implemented for the List : 1/4????
When i entered into BASIC PARAMETERS, i can change following variables parameters:
float Variable:26.0
byte var:50
boolean var:[0]

but i can not change the
list: 1/4

Another Observation is:
Saving and Loading from EEPROM is not functioning. For example when i presss change the parameters of variables SAVE TO EEPROM, then i shutdown the Arduino. When i power up the Arduino, and press LOAD THE EEPROM nothing happen. No values of BASIC PARAMETERS loaded.
Any thing wrong???

It seems to me that for lists does not make any sense manage the index. I have to introduce some correct behaviour. But still i do nt know what.
I'll check eeprom funcs

Okay:).. But kindly must look into the eeprom functionality.
Regards

I cannot replicate the problem. The eeprom functions seems to work properly in my environment.
Check the following:

  • sequence: SAVE TO EPROM/LOAD FROM EPROM . Once this "error" arose because the user mistakenly used the WRITE TO SERIAL entry instead of SAVE TO EPROM menu entry
  • after value changes did you confirmed with "enter" button?

brunialti:
I cannot replicate the problem. The eeprom functions seems to work properly in my environment.
Check the following:

  • sequence: SAVE TO EPROM/LOAD FROM EPROM . Once this "error" arose because the user mistakenly used the WRITE TO SERIAL entry instead of SAVE TO EPROM menu entry
  • after value changes did you confirmed with "enter" button?

I shall recheck again. However, i am quite sure that when first time the LOAD FROM EEPROM did not work then i cautiously SAVE TO EEPROM again and recheck.

My Questions:
1- Should I press the CONFIRM button after change in individual variable OR After change the values of All variables I only one type press the CONFIRM button?

currently i am pressing CONFIRM button after changes the values of all parameters (float, byte, boolean etc). I confirm here that my CONFIRM button is functional (By viewing Serial.println function).

After SAVE TO EEPROM did you powered off the system And then after powering up LOAD FROM EEPROM?... In my case the values retrieve so far as the system is powered on, once you powered off and restart the Arduino LOAD FROM EEPROM didn't work. Which it should be.