Go Down

Topic: Menu for Display (Read 40645 times) previous topic - next topic


Hi Oliver,
looking the example into your link I've understood how to pass the value :

- from a menu to the variable

but I don't understand into example:

- how pass the value from a variable to a menu ... :-(

when into the example call

"pwm_apply_user_input() "


void pwd_fn_ok(m2_el_fnarg_p fnarg)

so, if need to pass the value to my variable

[00][00] [00][00][00]
OK Cancel

how I can do ? this means that into ok function button I will fill my variable  ? and then will be immediatly displayed ?

Could you kindly pass me a simple just to understand ?

thanks for the support,


Passing a variable to M2tklib is (somehow) automatic. During definition of an element, such as M2_U8NUM, you pass a pointer to a variable:
Code: [Select]

uint8_t v;
M2_U8NUM(el_num, "", 0, 255, &v);

Variable "v" is connected to M2tklib. M2tklib will ALWAYS display the value of v. At any time you may assign a value to "v" and after the next call to the "draw" procedure it will display the current content of "v"
Controll flow would be:
1. Jump from top menu to sub dialog (e.g. time change menu)
2. During jump: Assign current sensor value (in your case RTC value) to "v" (prepare_user_input)
3. Let the use change "v" though m2tklib
4. If user pressed cancel, go back to main menu without any further action
5. If user presse ok, store value of "v" to the external device (e.g. RTC), jump back to main menu (apply_user_input).



Jan 29, 2013, 12:22 pm Last Edit: Jan 29, 2013, 02:42 pm by gnusso Reason: 1
Ciao Oliver,
from the logical stand point it's ok ... but to be honest I don't know how to realize it ... so:

Code: [Select]

uint8_t v;
M2_U8NUM(el_num, "r1", 0, 255, &v);

this is ok, because i use it normally into the menu i fill "v" when I push button ...

Now you mean ... for example into "Ok" button do something like this:

Code: [Select]

void viewdate{
v = RTC.get(DS1307_HR,true);

M2_BUTTON(el_num_zero, "f4", " Ok", viewdate);

then automatically into there will be the current date time ...

I thinks that soon i will be able to the test my menu with display and button ... you was telling me that the button will active when "low",
correct ? is necessary a resistor ? if you can provide to me a little schema will be great :-) ... so my understanding is this ...

correct ? just the idea what means active low could i test with serial menu ?

so then just add to the sketch this code:

Code: [Select]

uint8_t uiKeySelectPin = 10;
uint8_t uiKeyNextPin = 9;

and modify this code :
Code: [Select]

M2tk m2(&top_el_expandable_menu, m2_es_arduino_serial, m2_eh_2bs, m2_gh_arduino_serial);

with this :
Code: [Select]

M2tk m2(&top_el_expandable_menu, m2_es_arduino, m2_eh_2bs, m2_gh_arduino);

In order to use 2 button ...

if i'd like to use additional 2 but buttons just put this:
Code: [Select]

M2tk m2(&top_el_expandable_menu, m2_es_arduino, m2_eh_4bs, m2_gh_arduino);

and then declare additional buttons ?

thanks 10000



1) Ok button
Almost correct, except that you need to use the correct function prototype (see element reference for M2_BUTTON on the wiki page)  and probably you want to refer to a submenu. That means, that m2.setRoot() is missing
Code: [Select]
void viewdate(m2_el_fnarg_p fnarg){
v = RTC.get(DS1307_HR,true);
M2_BUTTON(el_num_zero, "f4", " Ok", viewdate);

2) External button
Connect one end of the button to an arduino pin
Connect the other end to ground (0V)
A resistor is NOT needed.

3) You need to assign the button with m2.setPin(<keyfunction>, <arduino_pin_number>)
see http://code.google.com/p/m2tklib/wiki/fnref#setPin

4) Adding a display.
Please follow this tutorial: http://code.google.com/p/m2tklib/wiki/t02lc
Note: The correct name for the graphics handler is "m2_gh_lc"!
Also take care to use m2_SetLiquidCrystal() as shown in the tutorial!



Good Morning Oliver :-) Great ! Thanks you ... :-)

so today I'll try and then I'll let you know :-)




I was imprecise. All dialog menus are accessed via their root element. So the answer is "el_list_date_disp" if you want to jump from main menu to "el_list_date_disp".



I've tried the function it's ok :-)

so I will try also with the button ... :-) but only a curiosity it's possible use the button with the serial ? or it's only possible via lcd ?



Not sure if i got your question right, but it is like this:
Usually you will
attach 2 or more hardware buttons and a physical LCD
With the serial monitor option you can do:
attach 2 or more hardware buttons and simulate the LCD via the serial monitor
simulate 2 ore more buttons via serial monitor and attach a physical LCD
simulate 2 ore more buttons via serial monitor and  simulate the LCD via the serial monitor



Good Morning Oliver,
I've did some test with LCD ... now I would ask to you if is possible change LCD pin ?

because inside my sketch I'm using "Virtual Wire Library" where as default use a

PIN 11 for rx and PIN 12 for tx and PIN 10 for push to talk ... well I've tried to specify other pint to use with the function but the display still to work not properly ... If i comment the part related to Virtual Wire everything is working well ...

So, what could advise me to do ? 

thanks for the support :-)

have nice a day,


Jan 31, 2013, 06:27 pm Last Edit: Jan 31, 2013, 06:45 pm by gnusso Reason: 1
So, now with this pin

LiquidCrystal lcd(10, 9, 3, 2, 1, 0);

can work ... but I didn't understand why for example im using arduino mega 2560 rev 3 if i try to use ... 22 24 38 40 42 44  cannot work ...

could be useful for arrange and use arduino at the top ...

so then when I'm in LCD mode I've strange issues with in a sub menu with a button ... so I retrive date time from RTC time to time it's ok and other times is not ok ...

this happened into serial menu ... it's very strange ... but the date should be correct ...

could i check ?
thanks gnux


Maybe have found seems a power connection issues now I need to check the circuit ... :-) i hope. ...


I don't think connecting the LCD to the main hardware serial port is a good idea.
The art of getting good answers lies in asking good questions.


I read though the last e-mails. For sure it seems to be strange, that the day number is 45, but what should be checked?



Ok Oliver, thanks for the information,
then I can use each pins that I want for lcd ?

Changing pin for lcd it's working ...

warm regards :-)


Hi Oliver,
changing the pin 0 and 1 the menu it's working ok now (i will consider this for the future :-) ) ...

Very helpfull :-)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131