Hi Oliver,
I am making progress. I have got a menu on my display and can navigate with my buttons OK.
I am struggling how to figure out how to use the menu to display some buttons to perform some functions.
I want 1 button to increase a value and one to decrease it.
I have tried the following code...
#include "U8glib.h"
#include "M2tk.h"
#include "utility/m2ghu8g.h"
U8GLIB_PCD8544 u8g(7, 6, 4, 5, 3); // SPI Com: SCK = 7, MOSI = 6, CS = 4, A0 = 5, Reset = 3
int bl = 9, blValue = 31;
uint8_t uiKeySelectPin = A4;
uint8_t uiKeyDownPin = A1;
uint8_t uiKeyUpPin = A2;
uint8_t uiKeyExitPin = A0;
//=================================================
// Forward declaration of the toplevel element
M2_EXTERN_ALIGN(top_el_menu);
// m2 object and constructor
M2tk m2(&top_el_menu, m2_es_arduino, m2_eh_4bs, m2_gh_u8g_bf);
//M2tk m2(&top_el_expandable_menu, m2_es_arduino_rotary_encoder, m2_eh_4bs, m2_gh_u8g_ffs);
//M2tk m2(&top_el_expandable_menu, m2_es_arduino, m2_eh_4bs, m2_gh_arduino_serial);
// Left entry: Menu name. Submenus must have a '.' at the beginning
// Right entry: Reference to the target dialog box (In this example all menus call the toplevel element again
m2_menu_entry m2_2lmenu_data[] =
{
{ "Show IP", NULL },
{ ". Address etc", &top_el_menu },
{ ". Internet", &top_el_menu },
{ "Ping", &top_el_menu },
{ ". x.x.x.1", &top_el_menu },
{ ". x.x.x.254", &top_el_menu },
{ ". Enter IP", &top_el_menu },
{ "Set IP", NULL },
{ ". DHCP", &top_el_menu },
{ ". Manual", &top_el_menu },
{ "Display", NULL },
{ ". Backlight", &el_backlight_menu },
{ NULL, NULL },
};
// The first visible line and the total number of visible lines.
// Both values are written by M2_2LMENU and read by M2_VSB
uint8_t m2_2lmenu_first;
uint8_t m2_2lmenu_cnt;
// M2_2LMENU definition
// Option l4 = four visible lines
// Option e15 = first column has a width of 15 pixel
// Option W43 = second column has a width of 43/64 of the display width
M2_2LMENU(el_2lmenu,"l6F3e14W56",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,65,102,'\0');
M2_SPACE(el_space, "W1h1");
//M2_VSB(el_vsb, "l6W2r1", &m2_2lmenu_first, &m2_2lmenu_cnt);
M2_LIST(list_2lmenu) = { &el_2lmenu, &el_space };
M2_HLIST(el_hlist, NULL, list_2lmenu);
M2_ALIGN(top_el_menu, "-1|2W64H64", &el_hlist);
void fn_bl_up(m2_el_fnarg_p fnarg) {
blValue = blValue + 32;
analogWrite(9, blValue);
}
void fn_bl_down(m2_el_fnarg_p fnarg) {
blValue = blValue - 32;
analogWrite(9, blValue);
}
void fn_goto_main_menu(m2_el_fnarg_p fnarg)
{
m2.setRoot(&top_el_menu);
}
void fn_goto_pwm_menu(m2_el_fnarg_p fnarg)
{
//m2.setRoot(&el_backlight_menu);
}
M2_BUTTON(el_btn_bl_up, "x1y1", "+", fn_bl_up);
M2_BUTTON(el_btn_bl_down, "x15y1", "-", fn_bl_down);
M2_BUTTON(el_btn_ok, "x30y1", "OK", fn_goto_main_menu);
M2_LIST(list) = { &el_btn_bl_up, &el_btn_bl_down, &el_btn_ok };
M2_XYLIST(list_element, NULL, list);
M2_ALIGN(el_backlight_menu, "-1|2W64H64", &list_element);
//M2tk m2(&list_element, m2_es_arduino, m2_eh_2bs, m2_gh_u8g_bf);
//=================================================
// Draw procedure, Arduino Setup & Loop
void draw(void) {
m2.draw();
}
void setup(void) {
// Connect u8glib with m2tklib
pinMode(bl, OUTPUT);
analogWrite(bl, blValue); //turns on backlight
m2_SetU8g(u8g.getU8g(), m2_u8g_box_icon);
// Assign u8g font to index 0
m2.setFont(0, u8g_font_5x7r);
//m2.setFont(0, u8g_font_04b_03r);
// Assign icon font to index 3
m2.setFont(3, u8g_font_m2icon_7);
// Setup keys
m2.setPin(M2_KEY_SELECT, uiKeySelectPin);
m2.setPin(M2_KEY_PREV, uiKeyUpPin);
m2.setPin(M2_KEY_NEXT, uiKeyDownPin);
m2.setPin(M2_KEY_EXIT, uiKeyExitPin);
/*
m2.setPin(M2_KEY_SELECT, 7);
m2.setPin(M2_KEY_ROT_ENC_A, 3);
m2.setPin(M2_KEY_ROT_ENC_B, 4);
*/
}
void loop() {
// menu management
m2.checkKey();
if ( m2.handleKey() != 0 ) {
u8g.firstPage();
do {
m2.checkKey();
draw();
} while( u8g.nextPage() );
}
}
When I compile I get an error :
m2tk_menu_list:41: error: 'el_backlight_menu' was not declared in this scope
Could you please point out where I have gone wrong?
Thanks,
Don