m2tklib and openGLCD m2.checkKey() error


hi have problem m2tklib

i using arduino mega , 128x64 graphic lcd , need menu glcd

i have found m2tklib cant use it. cant buttons while pressed.

code: [select]
/*

  menux2l.pde

  demonstration of m2_x2lmenu
 
  glcd example

  m2tklib = mini interative interface toolkit library
 
  copyright (c) 2013  olikraus@gmail.com

  program free software: can redistribute and/or modify
  under terms of gnu general public license published by
  free software foundation, either version 3 of license, or
  (at option) later version.

  program distributed in hope useful,
  without warranty; without implied warranty of
  merchantability or fitness particular purpose.  see the
  gnu general public license more details.

  should have received copy of gnu general public license
  along program.  if not, see <http://www.gnu.org/licenses/>.

*/
#include <stdlib.h> // itoa
#include <openglcd.h> // inform arduino ide use glcd library
#include "m2tk.h"
#include "utility/m2ghglcd.h"

uint8_t uikeyselectpin = 38;
uint8_t uikeydownpin = 39;
uint8_t uikeyuppin = 40;
uint8_t uikeyexitpin = 41;

//=================================================
// forward declaration of toplevel element
m2_extern_align(top_el_x2l_menu);


//=================================================
// define 3 user menus, demonstration.

m2_root(el_mnu1_sel, "t1", "menu 1 selected", &top_el_x2l_menu);
m2_align(top_el_mnu1_sel, "-1|1w64h64", &el_mnu1_sel);

m2_root(el_mnu2_sel, "t1", "menu 2 selected", &top_el_x2l_menu);
m2_align(top_el_mnu2_sel, "-1|1w64h64", &el_mnu2_sel);

m2_root(el_mnu3_sel, "t1", "menu 3 selected", &top_el_x2l_menu);
m2_align(top_el_mnu3_sel, "-1|1w64h64", &el_mnu3_sel);


//=================================================
uint8_t value = 0;
char buf[20];

// define callback procedure, returns menu entry value
const char *xmenu_value(uint8_t idx, uint8_t msg)

  if ( msg == m2_strlist_msg_get_str ) {
    strcpy(buf, " value: ");
    itoa((int)value, buf+strlen(buf), 10);
    return buf;
  }
  return "";
}

// define callback procedures increment , decrement value
const char *xmenu_inc(uint8_t idx, uint8_t msg) {
  if ( msg == m2_strlist_msg_select  ) {
      value++;
  }
  return "";
}

const char *xmenu_dec(uint8_t idx, uint8_t msg) {
  if ( msg == m2_strlist_msg_select  ) {
      value--;
  }
  return "";
}

//=================================================
// overall menu structure x2l menu

m2_xmenu_entry xmenu_data[] =
{
  { "menu 1", null, null }, /* expandable main menu entry */
  { ".", null, xmenu_value }, /* label of menu line returned callback procedure */
  { ". inc", null, xmenu_inc }, /* callback increments value */
  { ". dec", null, xmenu_dec }, /* callback decrements value */
  { "menu 2", null, null },
  { ". sub 2-1", &top_el_mnu1_sel, null },
  { ". sub 2-2", &top_el_mnu2_sel, null},
  { ". sub 2-3", &top_el_mnu3_sel, null },
  { null, null, null },
};

//=================================================
// main menu dialog box

// first visible line , total number of visible lines.
// both values written m2_x2lmenu , read m2_vsb
uint8_t el_x2l_first = 0;
uint8_t el_x2l_cnt = 3;

// m2_x2lmenu definition
// option l4 = 4 visible lines
// option e15 = first column has width of 15 pixel
// option w43 = second column has width of 43/64 of display width
m2_x2lmenu(el_x2l_strlist, "l4e15w43", &el_x2l_first, &el_x2l_cnt, xmenu_data, '+','-','\0');
m2_space(el_x2l_space, "w1h1");
m2_vsb(el_x2l_vsb, "l4w2r1", &el_x2l_first, &el_x2l_cnt);
m2_list(list_x2l) = { &el_x2l_strlist, &el_x2l_space, &el_x2l_vsb };
m2_hlist(el_x2l_hlist, null, list_x2l);
m2_align(top_el_x2l_menu, "-1|1w64h64", &el_x2l_hlist);


//=================================================
// m2 object , constructor
m2tk m2(&top_el_x2l_menu, m2_es_arduino, m2_eh_4bs, m2_gh_glcd_ffs);

//=================================================
// arduino setup , loop
void setup() {
  m2.setpin(m2_key_select, uikeyselectpin);
  m2.setpin(m2_key_next, uikeydownpin);
  m2.setpin(m2_key_prev, uikeyuppin);
  m2.setpin(m2_key_exit, uikeyexitpin); 
}

void loop() {
  m2.checkkey();
  if ( m2.handlekey() ) {
      m2.draw();
  }
}




code: [select]

uint8_t uikeyselectpin = 38;
uint8_t uikeydownpin = 39;
uint8_t uikeyuppin = 40;
uint8_t uikeyexitpin = 41;



my buttons connetted 38-41 on arduino mega

i tried pull ->http://www.arduino.cc/en/tutorial/pushbutton
and pull down ->http://arduino.cc/en/tutorial/button

no reaction :(

hi

the button need connect pin gnd. resistor not required.

oliver


Arduino Forum > Using Arduino > Displays > m2tklib and openGLCD m2.checkKey() error


arduino

Comments