Go Down

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

brunialti

#185
Sep 13, 2012, 03:18 pm Last Edit: Sep 13, 2012, 03:20 pm by brunialti Reason: 1
Ok. I'll try to let you fit 30+ menus ...  :smiley-fat:

tlhurley

Hello,

I have two questions about the code attached...

First... the section "DEFINE BOARD PINS FOR THE NAVIGATION BUTTONS" I have verified my electronics by continuity test to the pins on the ATMEL, ATMEGA328 and they are attached correctly with a 10K SIP Resistor pack to ground, the only button that works is the DOWN, I can scroll through the S1 menu but the CONFIRM, UP, ESCAPE, LEFT & RIGHT buttons do not work,  any assistance you can offer is greatly appreciated?

Second... the section ("// menu.addSplash(("TLHurley Engineering 12'\nEMZ Technologies 09/2012") menu.sbuf, 10000);") returns an error ( Expected ")" before "menu" ) why is this? I have the line commented out to verify the sketch compiles. I cannot find what the actual error is.

Thank you for any help,

Terry

Code: [Select]
[quote]
[color=#7E7E7E]//The full code is in library example file Sample MENWIZ.ino[/color]
#include <[color=#CC6600]Wire[/color].h>
#include <[color=#CC6600]LCD[/color].h>
#include <[color=#CC6600]LiquidCrystal[/color].h>
#include <[color=#CC6600]buttons[/color].h>
#include <MENWIZ.h>
#include <[color=#CC6600]EEPROM[/color].h>

[color=#7E7E7E]// DEFINE BOARD PINS FOR THE NAVIGATION BUTTONS (DCM2053 Pins shown below in notes)[/color]
#define UP_BUTTON_PIN       0  [color=#7E7E7E]// DCM2053 PIN 19[/color]
#define DOWN_BUTTON_PIN     1  [color=#7E7E7E]// DCM2053 PIN 20[/color]
#define LEFT_BUTTON_PIN     2  [color=#7E7E7E]// DCM2053 PIN 23[/color]
#define RIGHT_BUTTON_PIN    3  [color=#7E7E7E]// DCM2053 PIN 24[/color]
#define CONFIRM_BUTTON_PIN  4  [color=#7E7E7E]// DCM2053 PIN 22[/color]
#define ESCAPE_BUTTON_PIN   5  [color=#7E7E7E]// DCM2053 PIN 21[/color]


menwiz menu;
[color=#7E7E7E]// create lcd obj using LiquidCrystal lib[/color]
[color=#CC6600]LiquidCrystal[/color] lcd(7, 8, 9, 10, 11, 12);

[color=#7E7E7E]/*[/color]
[color=#7E7E7E]*LCD RS Pin - Dorkbaord D7[/color]
[color=#7E7E7E]*LCD EN Pin - Dorkbaord D8[/color]
[color=#7E7E7E]*LCD D4 Pin - Dorkbaord D9[/color]
[color=#7E7E7E]*LCD D5 Pin - Dorkbaord D10[/color]
[color=#7E7E7E]*LCD D6 Pin - Dorkbaord D11[/color]
[color=#7E7E7E]*LCD D7 Pin - Dorkbaord D12[/color]
[color=#7E7E7E]*LCD R/W Pin - GND[/color]
[color=#7E7E7E]*10K Resistor[/color]
[color=#7E7E7E]*ends to 5V and GND[/color]
[color=#7E7E7E]*/[/color]

[color=#7E7E7E]//instantiate global variables to bind to menu[/color]
[color=#CC6600]int[/color]      tp=0;
[color=#CC6600]float[/color]    f=26.0;
[color=#CC6600]boolean[/color]  bb=0;
[color=#CC6600]byte[/color]     b=50;

[color=#CC6600]void[/color] [color=#CC6600][b]setup[/b][/color](){
  [color=#CC6600]_menu[/color] *r,*s1,*s2;
  [color=#CC6600]_var[/color] *v;
  [color=#CC6600]int[/color]  mem;

  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]begin[/color](19200); 
  
  [color=#7E7E7E]// have a look on memory before menu creation[/color]
  [color=#CC6600][b]Serial[/b][/color].[color=#CC6600]println[/color](sizeof(menwiz));
  mem=menu.freeRam();
  
  [color=#7E7E7E]// inizialize the menu object (20 colums x 4 rows)[/color]
  menu.[color=#CC6600]begin[/color](&lcd,24,2);

  [color=#7E7E7E]//create the menu tree[/color]
  r=menu.[color=#CC6600]addMenu[/color]([color=#006699]MW_ROOT[/color],NULL,F([color=#006699]"MAIN MENU"[/color]));              [color=#7E7E7E]//create a root menu at first (required)[/color]
    s1=menu.[color=#CC6600]addMenu[/color](MW_SUBMENU,r,F([color=#006699]"MEASURE SUBMENU"[/color]));     [color=#7E7E7E]//add a child (submenu) node to the root menu[/color]
    
      s2=menu.[color=#CC6600]addMenu[/color]([color=#006699]MW_VAR[/color],s1,F([color=#006699]"Test list"[/color]));            [color=#7E7E7E]//add a terminal node (that is "variable"); [/color]
          s2->[color=#CC6600]addVar[/color]([color=#006699]MW_LIST[/color],&tp);                          [color=#7E7E7E]//create a variable of type "option list".. [/color]
          s2->[color=#CC6600]addItem[/color]([color=#006699]MW_LIST[/color],F([color=#006699]"option 1"[/color]));               [color=#7E7E7E]//add option to the OPTION LIST[/color]
          s2->[color=#CC6600]addItem[/color]([color=#006699]MW_LIST[/color],F([color=#006699]"option 2"[/color]));               [color=#7E7E7E]//add option to the OPTION LIST[/color]
          s2->[color=#CC6600]addItem[/color]([color=#006699]MW_LIST[/color],F([color=#006699]"option 3"[/color]));               [color=#7E7E7E]//add option to the OPTION LIST[/color]
          s2->[color=#CC6600]addItem[/color]([color=#006699]MW_LIST[/color],F([color=#006699]"option 4"[/color]));               [color=#7E7E7E]//add option to the OPTION LIST[/color]
          s2->[color=#CC6600]addItem[/color]([color=#006699]MW_LIST[/color],F([color=#006699]"option 5"[/color]));               [color=#7E7E7E]//add option to the OPTION LIST[/color]

      s2=menu.[color=#CC6600]addMenu[/color]([color=#006699]MW_VAR[/color],s1,F([color=#006699]"Test float var"[/color]));       [color=#7E7E7E]//add a terminal node (that is "variable"); [/color]
          s2->[color=#CC6600]addVar[/color](MW_AUTO_FLOAT,&f,11.00,100.00,0.5); [color=#7E7E7E]//create a variable of type "float number"... [/color]
                                                         [color=#7E7E7E]//...associated to the terminal node and bind it to the app variable "f" of type float[/color]
      s2=menu.[color=#CC6600]addMenu[/color]([color=#006699]MW_VAR[/color],s1,F([color=#006699]"Test byte var"[/color]));        [color=#7E7E7E]//add a terminal node (that is "variable"); [/color]
          s2->[color=#CC6600]addVar[/color](MW_AUTO_BYTE,&b,25,254,10);         [color=#7E7E7E]//create a variable of type "byte"...[/color]
                                                         [color=#7E7E7E]//...associated to the terminal node and bind it to the app variable "b" of typr byte[/color]
      s2=menu.[color=#CC6600]addMenu[/color]([color=#006699]MW_VAR[/color],s1,F([color=#006699]"Test boolean var"[/color]));     [color=#7E7E7E]//add a terminal node (that is "variable"); [/color]
          s2->[color=#CC6600]addVar[/color](MW_BOOLEAN,&bb);                    [color=#7E7E7E]//create a variable of type "boolean" [/color]
                                                         [color=#7E7E7E]//...associated to the terminal node and bind it to the app variable "bb" of type boolean[/color]
    s1=menu.[color=#CC6600]addMenu[/color]([color=#006699]MW_VAR[/color],r,F([color=#006699]"WRITE TO SERIAL"[/color]));             [color=#7E7E7E]//add a terminal node (that is "variable") create an "action" associated to the terminal node... [/color]
      s1->[color=#CC6600]addVar[/color](MW_ACTION,act);                         [color=#7E7E7E]//the act function as default will be called when enter button is pushed[/color]

    s1=menu.[color=#CC6600]addMenu[/color]([color=#006699]MW_VAR[/color],r,F([color=#006699]"SAVE TO EPROM"[/color]));           [color=#7E7E7E]//add a terminal node (that is "variable") create an "action" associated to the terminal node... [/color]
      s1->[color=#CC6600]addVar[/color](MW_ACTION,savevar);                     [color=#7E7E7E]//the act function as default will be called when enter button is pushed[/color]

    s1=menu.[color=#CC6600]addMenu[/color]([color=#006699]MW_VAR[/color],r,F([color=#006699]"LOAD FROM EEPROM"[/color]));        [color=#7E7E7E]//add a terminal node (that is "variable") create an "action" associated to the terminal node... [/color]
      s1->[color=#CC6600]addVar[/color](MW_ACTION,loadvar);                     [color=#7E7E7E]//the act function as default will be called when enter button is pushed[/color]

  [color=#7E7E7E]//declare navigation buttons (required)[/color]
  menu.navButtons(UP_BUTTON_PIN,DOWN_BUTTON_PIN,LEFT_BUTTON_PIN,RIGHT_BUTTON_PIN,ESCAPE_BUTTON_PIN,CONFIRM_BUTTON_PIN);


 [color=#7E7E7E]// menu.addSplash(("TLHurley Engineering 12'\nEMZ Technologies 09/2012") menu.sbuf, 10000);[/color]
  }

  }

[/quote]

brunialti

at first glance:
do not use the digital pins 0,1 they are reserved for serial comms. Use the pins starting from 7 instead;
let me know

p.s. try to insert the code without the color markups!

backbone

#188
Sep 27, 2012, 08:17 pm Last Edit: Sep 28, 2012, 08:46 am by backbone Reason: 1
For those who are interessted here the code to use for analog value simulated push buttons to control Menwiz.
Maybe good idea to put it in the manual or in the samples?

edit one error in the first line of void loop. check
// NAVIGATION MANAGEMENT & DRAWING ON LCD. NOT BLOCKING has to be the first in the void loop
  menu.draw();

Code: [Select]
/*

Schematic:

/*

This is the way the ressitor ladder is used.
*
*   analogPin A0                 +5 V
*      |                         |
*      |                         \
*      ----------------          /  
*                     |          \  1K
*                     |          /
*                     |          \
*                     |____ \____|
*                     |   SW1    |
*                     |          \
*                     |          /  
*                     |          \  1K
*                     |          /
*                     |          \
*                     |____ \____|
*                     |   SW2    |
*                     |          |
*                     |          \
*                     |          /  
*                     |          \  1K
*                     |          /
*                     |          \
*                     |____ \____|
*                     |   SW3    |
*                     |          |
*                     |          \
*                     |          /  
*                     |          \  1K
*                     |          /
*                     |          \
*                     |____ \____|
*                         SW4    |
*                                |
*                                \
*                                /  
*                                \  1K
*                                /
*                                \
*                                |
*                                |
*                                |
*                                |
*                                |
*                              _____  
*                               ___     ground
*                                _
*
*/

// +++++++ Libaries included
#include <Wire.h>
//INSERT ALL THE LIBARIES AFTER INCLUDING WIRE LIB (MENWIZ request)
#include <LiquidCrystal_I2C.h>
#include <buttons.h>
#include <MENWIZ.h>
#include <EEPROM.h>

// Create global object for menu and lcd
menwiz menu;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7, backlightpin, polarity 4 x 20 LCD

boolean wr=0; // Instantiate global variables to bind to menu

const int buttonPin = A0;             // 4 button switch circuit input connected to analog pin 0
const int led13Pin = 13;              // the number of the LED output pin

boolean buttonBlock = 0;
boolean buttonAct = 0; // flag 1
boolean stopMenu = 0; // flag 2
byte buttonPressed = 0;  // which button was pressed
byte lastButtonPressed = 0; // prev button pressed
int buttonValue = 0;  // read value from analog port for the 4 navigation pushbuttons
long menuOffTime = 0;  //used for timer

extern byte MW_navbtn;  //needed to run the software key navigation in Menwiz



void setup()
{
 Serial.begin(9600);                       // Output to serial writing

 digitalWrite((54), HIGH);  // enable the 20k internal pullup for MEGA board for analog port A0
 // digitalWrite((A0), HIGH);  // enable the 20k internal pullup for UNO based board for analog port A0

 //++++++++++++++++++++Menu and LCD  
 char b[84];
 _menu *r,*s1,*s2;

 // initialize the menu object ( 4 x rows x 20 colums LCD)
 menu.begin(&lcd,20,4);
 menu.addUsrNav(navMenu);
 MW_navbtn=4;  // force 4 or 6 buttons mode for menu navigation -> MW_navbtn=4; or MW_navbtn=6;

 //create the menu tree
 r=menu.addMenu(MW_ROOT,NULL,F("MAIN MENU"));                      //create a root menu at first (required)

 //---------------  
 s1=menu.addMenu(MW_SUBMENU,r,F("SET1"));                        //add a submenu node 1 to the root menu
 s2=menu.addMenu(MW_VAR,s1,F("MD"));                         //add a terminal node in the menu tree (that is "variable");
 s2=menu.addMenu(MW_VAR,s1,F("BR"));                         //add a terminal node in the menu tree (that is "variable");
 s2=menu.addMenu(MW_VAR,s1,F("RH"));                         //add a terminal node in the menu tree (that is "variable");

 //---------------
 s1=menu.addMenu(MW_SUBMENU,r,F("SET2"));                    //add a submenu node 2 to the root menu
 s2=menu.addMenu(MW_VAR,s1,F("CP"));                         //add a terminal node in the menu tree (that is "variable");
 s2=menu.addMenu(MW_VAR,s1,F("DB"));                         //add a terminal node in the menu tree (that is "variable");
 s2=menu.addMenu(MW_VAR,s1,F("SQ"));                         //add a terminal node in the menu tree (that is "variable");

 //---------------
 s1=menu.addMenu(MW_SUBMENU,r,F("SET3"));                    //add a submenu node 3 to the root menu
 s2=menu.addMenu(MW_VAR,s1,F("RS"));                         //add a terminal node in the menu tree (that is "variable");
 s2=menu.addMenu(MW_VAR,s1,F("RCALIB"));                     //add a terminal node in the menu tree (that is "variable");
 s2=menu.addMenu(MW_VAR,s1,F("SCALIB"));                     //add a terminal node in the menu tree (that is "variable");


 //++++++ Splash screen +++++++
 
 sprintf(menu.sbuf,"TEST minimum menu\nwith 4 or 6\nanalog push buttons\n",1);
 menu.addSplash((char *) menu.sbuf, 1000);

 //++++++ Userscreen ++++++++++
 // create an user define screen callback to activate after X secs since last button push
 menu.addUsrScreen(msc,3000);

 pinMode(led13Pin, OUTPUT);                // initialize the led as a output control pin
}

void loop()    
{
// NAVIGATION MANAGEMENT & DRAWING ON LCD. NOT BLOCKING has to be the first in the void loop
  menu.draw();
/*
 put your regular code here
  */
 readButtons();
}

//  ++++++ functions +++++++

void readButtons()

// ++++ Control 4 buttons ++++
{
 lastButtonPressed = buttonPressed;

 /*
 Analog values representing the pushbutton value are depending on the resitor value used.
  Test the values first with the serial.monitor
  */
 buttonValue = analogRead(buttonPin); //analog value to simulate the pushed buttons

 if(buttonValue >= 1000)
 {
   buttonPressed = 0;
   noButtonPressed(); // is calling an extra fucntion
 }
 else  if(buttonValue >= 900 & buttonValue <= 950)
 {
   buttonPressed = 1;
   buttonAct = 1; // set the menu flag1
 }
 else if(buttonValue >= 800 & buttonValue <=900)
 {    
   buttonPressed = 2;
   buttonAct = 1; // set the menu flag1
 }
 else if(buttonValue >= 700 & buttonValue <=800)
 {    
   buttonPressed = 3;
   buttonAct = 1; // set the menu flag1
 }
 else if(buttonValue >= 600 & buttonValue <=700)
 {    
   buttonPressed = 4;
   buttonAct = 1; // set the menu flag1
 }
}

int noButtonPressed()
{
 return MW_BTNULL;
}

int navMenu() // called from menu.draw
{
 /*
  As soon as a button is pushed the first time flag 1 is set to HIGH and if the buttonnumber is not 0 then a timer is started.
  The menu action then should only be performed once.
  After 2000 msecs the flag will be set to LOW and a new buttonpush can be processed.
  Menu action is blocked for 2000 msec even if the same button is being kept pressed for 2000 msecs by flag2.
  */

 long menublockTime = millis();

 if (buttonAct == 1 && buttonPressed != 0 && stopMenu == 0)  // we have a state were we process a menu navigation step once and block it for 2 secs
 {
   digitalWrite(led13Pin,HIGH);  // set timer led ON
   menuOffTime = menublockTime  + 2000; //start the timer. You can change this blocking time to your convenience but do not make it lower aa 200 msecs
   stopMenu = 1;

   switch (buttonPressed)
   {
   case 1: // Up
     return MW_BTU;
     break;
   case 2: // Confirm
     return MW_BTC;
     break;
   case 3: // Down
     return MW_BTD;
     break;    
   case 4: // Escape
     return MW_BTE;
     break;
   }
 }

 if (menuOffTime != 0  &&  menublockTime  > menuOffTime)  //  Reset of the timer so a new menu action can be processed
 {
   buttonAct = 0; // resets the flag 1
   buttonPressed = 0;
   menuOffTime = 0;  // resets timer to zero
   stopMenu = 0;
   digitalWrite(led13Pin,LOW);  // set timer led OFF
 }
}

// user defined default screen.
void msc()
{
 sprintf(menu.sbuf,"User screen\nUptime (s): %ld\nFree mem  : %d\n\n",millis()/1000,(int)menu.freeRam());
 menu.drawUsrScreen(menu.sbuf);
}
Never to old to learn and I learn every day

tlhurley

Regarding reply #186 and 187...

Thank you,

I was not aware of the conflict with dual purposing the D0 (RXD) and D1 (TXD) for button use. I am using Digital Pins 7-12 for the display output, is there something in your Libraries that prevent the use of these pins for button use?

also, I was wondering about the addsplash issue in my previous post, can you address the line of code and tell me why I get the error?

Thank you,

Terry

Go Up