I'm using a 16x2 LCD and here is the menu concept I came up with using a knob and a button.
I have 6 menus to display. Both lines of each menu have a single label:value structure, each of varying length. So I have a total of 12 variables that I want the user to be able to edit using the knob and button.
The knob should initially move an underscore through each digit of the values (skipping over labels), and roll over to the next or previous menu. When the cursor underlines the desired digit in the value, the button is pressed, turning the cursor to a highlight, and the knob will now edit the value, incrementing by the appropriate amount. Finally, the button will exit the edit mode and return the original cursor and knob behavior.
I made a function that will scroll the cursor through each character of the LCD as a start.
The first question I have may not be important, but it seems there would be a much more efficient way to do this.
void rollMenu() {
LCD.print("?c1"); // set cursor: 0=off, 1=underline, 2=highlight
long newPosition = myEnc.read();
oldPosition = newPosition;
while (mode == 1) {
long newPosition = myEnc.read();
if (newPosition < oldPosition) {
p--;
if (p < 0) {
p = 31;
}
}
if (newPosition > oldPosition) {
p++;
if (p > 31) {
p = 0;
}
}
if (p == 0) {
LCD.print("?x00?y0");
}
if (p == 1) {
LCD.print("?x01?y0");
}
if (p == 2) {
LCD.print("?x02?y0");
}
if (p == 3) {
LCD.print("?x03?y0");
}
if (p == 4) {
LCD.print("?x04?y0");
}
if (p == 5) {
LCD.print("?x05?y0");
}
if (p == 6) {
LCD.print("?x06?y0");
}
if (p == 7) {
LCD.print("?x07?y0");
}
if (p == 8) {
LCD.print("?x08?y0");
}
if (p == 9) {
LCD.print("?x09?y0");
}
if (p == 10) {
LCD.print("?x10?y0");
}
if (p == 11) {
LCD.print("?x11?y0");
}
if (p == 12) {
LCD.print("?x12?y0");
}
if (p == 13) {
LCD.print("?x13?y0");
}
if (p == 14) {
LCD.print("?x14?y0");
}
if (p == 15) {
LCD.print("?x15?y0");
}
if (p == 16) {
LCD.print("?x00?y1");
}
if (p == 17) {
LCD.print("?x01?y1");
}
if (p == 18) {
LCD.print("?x02?y1");
}
if (p == 19) {
LCD.print("?x03?y1");
}
if (p == 20) {
LCD.print("?x04?y1");
}
if (p == 21) {
LCD.print("?x05?y1");
}
if (p == 22) {
LCD.print("?x06?y1");
}
if (p == 23) {
LCD.print("?x07?y1");
}
if (p == 24) {
LCD.print("?x08?y1");
}
if (p == 25) {
LCD.print("?x09?y1");
}
if (p == 26) {
LCD.print("?x10?y1");
}
if (p == 27) {
LCD.print("?x11?y1");
}
if (p == 28) {
LCD.print("?x12?y1");
}
if (p == 29) {
LCD.print("?x13?y1");
}
if (p == 30) {
LCD.print("?x14?y1");
}
if (p == 31) {
LCD.print("?x15?y1");
}
oldPosition = newPosition;
}
}
Now, I'll have to keep in mind that, depending on which of the 4 menus is displayed, the cursor will need to skip different parts of the display. I could do that by adding another variable (menu) and sprinkling in additional tests to see which menu is current (I'd be able to increment/decrement the menu number the same time as p). Another way is to duplicate the code block above for each menu, or last I thought of scrapping the menu # idea and just counting every value digit (about 70 digits total).
Some other thought I have:
I'll have to create another function to update the entire menu when they change to the next.
I'll have to create another function to update the actual variable the correct amount. I was thinking again of if statement (i.e., if p = 5, x = x + 1000; if p = 6, x = x + 100, etc.).
Edit: oh yeah, and back fill or pad the numbers...
But there is likely a much better approach to the whole thing?