Go Down

Topic: How make simple menus with LCD (Read 1 time) previous topic - next topic



I have Arduino Uno & ARD 216 Display kit

Display kit was include five button. They have connected on analog port "0". All button have a own resistor.
That gives alla button a different value.
Buttons are: up, down, left, right and select

But "i have a dream"...

I made a gauge, what calculate a propeller slip.
All works how i wants, but now is time to upgrade that code.

const double nousu = 23;
const double gear = 2.4;
const double kerroin = 1215.2;
const double nopeus = 15;
const double kierros = 5818;
const double yla = (gps.f_speed_knots()*gear*kerroin); // Luistolaskelman jakoviivan yläpuoli = 145824
const double ala = (rpm*nousu);

That bold text have to change with menuselect?

How i do simple menu, which change value (gear between 1.00 to 2.65 and nousu between 5 to 35)

Christmas greetings from Finland


So, use 'select' to toggle between 'display', 'configure nousu' and 'configure gear' modes.

In display mode your sketch does the same thing it currently does. This is the normal, working mode and would be the default at startup.

In the other modes you would display a label and the current value for the corresponding configuration parameter. If the up button is pressed, increment the value. If the down button is pressed, decrement it. To avoid pressing the buttons thousands of times you could design it so that if you hold the button down the value is changed by one at some interval, perhaps 4Hz. If the button is held down longer than a few seconds. the least significant digit is rounded down to zero and the changes are made in multiples of ten. If the button is held down for even longer, the least significant two digits are rounded down and the changes are made in steps of 100. So you can make small changes by holding the button down briefly, but still make big changes without waiting all day.

Presumably you'd want to save the updated values and it would make sense to save them in EEPROM. In that case it would be sensible to save the updated value when the mode switch is pressed to finish updating it.

To implement these three modes you'd need some code in loop() to poll and debounce the mode switch and increment a 'current mode' variable each time the switch was pressed (edge detection). Then use a switch statement to execute the code corresponding to the current mode. I'd suggesting putting the code for each mode in a separate function and just calling it from the switch statement. Each of these functions should be designed so that they complete promptly, which means no using delay() and no blocking (waiting) for external events. You'd need to use the asynchronous approach demonstrated in 'blink without delay' to carry out timed actions.


There are several menu libs available. M2tklib is one of them: http://code.google.com/p/m2tklib/.
The element M2_U8NUM (http://code.google.com/p/m2tklib/wiki/elref#U8NUM) could be used in your case.
Have a look at the tutorials in order to learn how to use M2tklib.


Go Up