MenWiz Programming Question

Hello All,

I'm currently developing my own DIY aquarium controller. I'm using MENWIZ menu library to generate the various options and display them on a 20x4 screen. I've gone through the discussions on a couple of forums regarding the MENWIZ library and I'm comfortable using it (So far).

Just one question though, I'm currently using the 6 button navigational options, and every time I press any of the buttons (up, down, right, left, enter or escape) the menu is displayed. Is it possible that the menu is displayed only when the enter key is pressed. Better still if the menu is displayed only if the enter key is held down for say 5 or more seconds.

Any help, guidance would be appreciated.

I'm using the standard/example code so far, but if some one is interested in looking at my code, i'd be more than happy to share.

Wish all a good start to the year

Thanks
Ritzy

s it possible that the menu is displayed only when the enter key is pressed

Yes.

Better still if the menu is displayed only if the enter key is held down for say 5 or more seconds.

Yes.

Any help, guidance would be appreciated.

My crystal ball says that you need to fix lines 27, 299, and 32452351463477. Hmmm. I'm not sure about that last one. Maybe that says elephant.

Thank for the quick response Paul, but line 27 and 299 where ? .h or .cpp ? Any examples to go with it ?
:slight_smile:
Ritzy

but line 27 and 299 where ? .h or .cpp ?

That's an excellent question. Do you have any others?

Any examples to go with it ?

What is "it"?

When you post some code, I'm confident that we'll actually get somewhere.

Hi, I looked in my crystal ball, PaulS (he doesn't have one), is referring to your program that we would have to look at to see how to implement what you want.

Tom.... :slight_smile:

:)) Kindda slow this morning (or evening here) - or is that always?? wonders

Anyways here is the code. Its a modified code from the MenWiz library - quick_tour.ino. Not very well commented, but I could get working on that.

Currently the UserScreen is displayed after 5 seconds. As soon as i hit any of the navigational buttons the menu shows up. What im looking for is help on making the menu appear only after the enter button is pushed.

///The full code is in library example file Quick_tour.ino
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <buttons.h>
#include <MENWIZ.h>
#include <EEPROM.h>

// DEFINE ARDUINO PINS FOR THE NAVIGATION BUTTONS
#define UP_BOTTON_PIN       2
#define DOWN_BOTTON_PIN     3
#define LEFT_BOTTON_PIN     4 
#define RIGHT_BOTTON_PIN    5
#define CONFIRM_BOTTON_PIN  6
#define ESCAPE_BOTTON_PIN   7

menwiz tree;
// create lcd obj using LiquidCrystal lib
LiquidCrystal_I2C lcd(0x20, 4, 5, 6, 0, 1, 2, 3, 11, POSITIVE);

int  list,sp=110;

void setup(){
  _menu *r,*s1,*s2;

  Serial.begin(19200);    
  tree.begin(&lcd,20,4); //declare lcd object and screen size to menwiz lib

  r=tree.addMenu(MW_ROOT,NULL,F("Root"));
    s1=tree.addMenu(MW_SUBMENU,r, F("Node1"));
      s2=tree.addMenu(MW_VAR,s1, F("Node3"));
        s2->addVar(MW_LIST,&list);
        s2->addItem(MW_LIST, F("Option1"));
        s2->addItem(MW_LIST, F("Option2"));
        s2->addItem(MW_LIST, F("Option3"));
      s2=tree.addMenu(MW_VAR,s1, F("Node4"));
        s2->addVar(MW_AUTO_INT,&sp,0,120,10);  
    s1=tree.addMenu(MW_VAR,r, F("Node2"));
      s1->addVar(MW_ACTION,myfunc);
       tree.navButtons(UP_BOTTON_PIN,DOWN_BOTTON_PIN,LEFT_BOTTON_PIN,RIGHT_BOTTON_PIN,ESCAPE_BOTTON_PIN,CONFIRM_BOTTON_PIN);
tree.addUsrScreen(displayscreen,5000);  

}
  

void loop(){
  tree.draw(); 
  }

void myfunc(){
  Serial.println("ACTION FIRED");
  }
  void displayscreen(){
    lcd.setCursor(0,0);
  lcd.print("waiting for inputs  ");
  lcd.setCursor(0,1);
  lcd.print("                    ");
    lcd.setCursor(0,2);
  lcd.print("                    ");
    lcd.setCursor(0,3);
  lcd.print("                    ");

  
  }
}

Currently the UserScreen is displayed after 5 seconds.

It doesn't appear that it should take that long. Once the bootloader is done, init() is called, then setup(), then loop() is called over and over. It is loop() that is immediately displaying the menu.

Put tree.draw() in the body of an if statement that is true only when the switch is pressed.

Even better is to look at the state change detection example to learn how to detect when the switch becomes pressed (and note the time). You can use the same technique to detect when the switch is released.

You can look at the blink without delay example to see how to determine if it has been 5 seconds since the switch became pressed, and take action then.

Keep in mind that 5 seconds is a LLLOOONNNGGG time to hold a switch. 2 or 3 would be more user-friendly.

thanks Paul. I might have expressed "Currently the UserScreen is displayed after 5 seconds." incorrectly.

I totally agree with you that the sketch loads up pretty fast. No doubt about that. What it does do is, load the menu first (after some loading animation I've not uploaded), then there is a gap of about 5 seconds and then the UserScreen (which does the temperature collection and time and date display etc) is shown. For now, till I get the other portion of the code working, this would work.

What I was referring to was that if I were to press any of the input keys (up,down...confirm) the menu shows up. I wanted to the menu to show up only when I press the enter key (connected to pin 6).

I will try putting the tree.draw() in a body of a if statement. I think that should work. Will keep posting about the success (or failure).

Also, will try the state change of the pin example. Agree with you that 5 seconds would be long, but that was just a start :slight_smile:

Ritzy.