Simple LCD Menuing

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?

C2:
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?

Have a look at the menuing system that LiuDR has built - this will answer all your questions

Craig

Thanks! There is truly a lot to read from Dr. Li!

Looking at this example, it seems he uses switch cases, but a similar approach...

Just another version using switch case:

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;
      }
    }
    switch (p){
    case 0:
      LCD.print("?x00?y0");
    case 1:
      LCD.print("?x01?y0");
    case 2:
      LCD.print("?x02?y0");
    case 3:
      LCD.print("?x03?y0");
    case 4:
      LCD.print("?x04?y0");
    case 5:
      LCD.print("?x05?y0");
    case 6:
      LCD.print("?x06?y0");
    case 7:
      LCD.print("?x07?y0");
    case 8:
      LCD.print("?x08?y0");
    case 9:
      LCD.print("?x09?y0");
    case 10:
      LCD.print("?x10?y0");
    case 11:
      LCD.print("?x11?y0");
    case 12:
      LCD.print("?x12?y0");
    case 13:
      LCD.print("?x13?y0");
    case 14:
      LCD.print("?x14?y0");
    case 15:
      LCD.print("?x15?y0");
    case 16:
      LCD.print("?x00?y1");
    case 17:
      LCD.print("?x01?y1");
    case 18:
      LCD.print("?x02?y1");
    case 19:
      LCD.print("?x03?y1");
    case 20:
      LCD.print("?x04?y1");
    case 21:
      LCD.print("?x05?y1");
    case 22:
      LCD.print("?x06?y1");
    case 23:
      LCD.print("?x07?y1");
    case 24:
      LCD.print("?x08?y1");
    case 25:
      LCD.print("?x09?y1");
    case 26:
      LCD.print("?x10?y1");
    case 27:
      LCD.print("?x11?y1");
    case 28:
      LCD.print("?x12?y1");
    case 29:
      LCD.print("?x13?y1");
    case 30:
      LCD.print("?x14?y1");
    case 31:
      LCD.print("?x15?y1");
    }
    oldPosition = newPosition;
  }
}

have a look at exercise 9.2 w/video around the middle of the page.
http://tronixstuff.wordpress.com/2010/06/06/getting-started-with-arduino-chapter-nine/

C2:
Thanks! There is truly a lot to read from Dr. Li!

Looking at this example, it seems he uses switch cases, but a similar approach...

Phi-menu | LiuDr Electronic Solutions LLC Official Blog

yep he is a very busy coder !

Craig

I kept thinking there has to be an easier way...or at least one that reuses more code and is more efficient.

The code below cycles through all the menus. One function watches the encoder and calls LCDp(); to update the LCD cursor position. A third function writes the current full two line menu whenever needed.

void rollMenu() {
  menu();
  LCD.print("?c2");                  // set cursor: 0=off, 2=underline, 1=highlight
  delay(100);
  LCDp();
  long newPosition = myEnc.read();
  oldPosition = newPosition;
  while (mode == 1) {
    long newPosition = myEnc.read();
    if (newPosition < oldPosition) {
      p--;
      if (p < 0) {
        p = 60;
      }
      LCDp();
    }
    if (newPosition > oldPosition) {
      p++;
      if (p > 60) {
        p = 0;
      }
      LCDp();
    }
    oldPosition = newPosition;
  }
}

void LCDp() {
  switch (p){
  case 0: // F0
    menu();
    LCD.print("?x03?y0");
    delta = 10000000;
    break;
  case 1:
    LCD.print("?x04?y0");
    delta = 1000000;
    break;
  case 2:
    LCD.print("?x05?y0");
    delta = 100000;
    break;
  case 3:
    LCD.print("?x06?y0");
    delta = 10000;
    break;
  case 4:
    LCD.print("?x07?y0");
    delta = 1000;
    break;
  case 5:
    LCD.print("?x08?y0");
    delta = 100;
    break;
  case 6:
    LCD.print("?x09?y0");
    delta = 10;
    break;
  case 7:
    LCD.print("?x10?y0");
    delta = 1;
    break;
  case 8: //P0
    LCD.print("?x04?y1");
    delta = 10;
    break;
  case 9:
    LCD.print("?x05?y1");
    delta = 1;
    break;
  case 10:
    menu();
    LCD.print("?x07?y1");
    delta = 0;
    break;    
  case 11: // F1
    menu();
    LCD.print("?x03?y0");
    break;
  case 12:
    LCD.print("?x04?y0");
    break;
  case 13:
    LCD.print("?x05?y0");
    break;
  case 14:
    LCD.print("?x06?y0");
    break;
  case 15:
    LCD.print("?x07?y0");
    break;
  case 16:
    LCD.print("?x08?y0");
    break;
  case 17:
    LCD.print("?x09?y0");
    break;
  case 18:
    LCD.print("?x10?y0");
    break;
  case 19:  // F2
    LCD.print("?x03?y1");
    break;
  case 20:
    LCD.print("?x04?y1");
    break;
  case 21:
    LCD.print("?x05?y1");
    break;
  case 22:
    LCD.print("?x06?y1");
    break;
  case 23:
    LCD.print("?x07?y1");
    break;
  case 24:
    LCD.print("?x08?y1");
    break;
  case 25:
    LCD.print("?x09?y1");
    break;
  case 26:
    menu();
    LCD.print("?x10?y1");
    break;
  case 27: // SWPTIME to DWLTIME
    menu();
    LCD.print("?x08?y0");
    break;
  case 28:
    LCD.print("?x09?y0");
    break;
  case 29:
    LCD.print("?x10?y0");
    break;
  case 30:
    LCD.print("?x11?y0");
    break;
  case 31:
    LCD.print("?x12?y0");
    break;
  case 32:
    LCD.print("?x13?y0");
    break;
  case 33:
    LCD.print("?x08?y1");
    break;
  case 34:
    LCD.print("?x09?y1");
    break;
  case 35:
    LCD.print("?x10?y1");
    break;
  case 36:
    LCD.print("?x11?y1");
    break;
  case 37:
    LCD.print("?x12?y1");
    break;
  case 38:
    menu();
    LCD.print("?x13?y1");
    break;
  case 39: // #STEPS
    menu();
    LCD.print("?x07?y0");
    break;
  case 40:
    LCD.print("?x08?y0");
    break;
  case 41:
    LCD.print("?x09?y0");
    break;
  case 42:
    LCD.print("?x10?y0");
    break;
  case 43:
    LCD.print("?x11?y0");
    break;
  case 44:
    LCD.print("?x12?y0");
    break;
  case 45:
    LCD.print("?x13?y0");
    break;
  case 46:
    LCD.print("?x14?y0");
    break;
  case 47: // SZ
    LCD.print("?x03?y1");
    break;
  case 48:
    LCD.print("?x04?y1");
    break;
  case 49:
    LCD.print("?x05?y1");
    break;
  case 50:
    LCD.print("?x06?y1");
    break;
  case 51:
    LCD.print("?x07?y1");
    break;
  case 52:
    LCD.print("?x08?y1");
    break;
  case 53:
    LCD.print("?x09?y1");
    break;
  case 54:
    menu();
    LCD.print("?x10?y1");
    break;
  case 55: // P1
    menu();
    LCD.print("?x04?y0");
    break;
  case 56:
    LCD.print("?x05?y0");
    break;
  case 57:
    LCD.print("?x07?y0");
    break;
  case 58: //P2
    LCD.print("?x04?y1");
    break;
  case 59:
    LCD.print("?x05?y1");
    break;
  case 60:
    menu();
    LCD.print("?x07?y1");
    break;
  }
}



void config() {
  mode = 1;
  menu();
}

void menu() {
  if (p >= 0 && p < 11) {
    LCD.print("?f");                   // clear the LCD
    LCD.print("?x00?y0");
    LCD.print("F0:");
    LCD.print(long(freq));
    LCD.print("?x14?y0");
    LCD.print("Hz");
    LCD.print("?x00?y1");
    LCD.print("P0: ");
    LCD.print("--.--");
    LCD.print("?x13?y1");
    LCD.print("dBm");
  }

  if (p >= 11 && p < 27) {
    LCD.print("?f");                   // clear the LCD
    LCD.print("?x00?y0");
    LCD.print("F1:");
    LCD.print(long(F1));
    LCD.print("?x14?y0");
    LCD.print("Hz");
    LCD.print("?x00?y1");
    LCD.print("F2:");
    LCD.print(long(F2));
    LCD.print("?x14?y0");
    LCD.print("Hz");
  }

  if (p >= 27 && p < 39) {
    LCD.print("?f");                   // clear the LCD
    LCD.print("?x00?y0");
    LCD.print("SWPTIME:");
    LCD.print(long(timeSweep));
    LCD.print("?x14?y0");
    LCD.print("us");
    LCD.print("?x00?y1");
    LCD.print("DWLTIME:");
    LCD.print(long(timeDwell));
    LCD.print("?x14?y1");
    LCD.print("us");
  }

  if (p >= 39 && p < 55) {
    LCD.print("?f");                   // clear the LCD
    LCD.print("?x00?y0");
    LCD.print("#STEPS:");
    LCD.print(long(steps));
    LCD.print("?x00?y1");
    LCD.print("SZ:");
    LCD.print(long(fStep));
    LCD.print("?x14?y1");
    LCD.print("Hz");
  }

  if (p >= 55 && p < 61) {
    LCD.print("?f");                   // clear the LCD
    LCD.print("?x00?y0");
    LCD.print("P1: ");
    LCD.print("--.--");
    LCD.print("?x13?y0");
    LCD.print("dBm");
    LCD.print("?x00?y1");
    LCD.print("P2: ");
    LCD.print("--.--");
    LCD.print("?x13?y1");
    LCD.print("dBm");
  }
}

You'll notice in the LCDp(); function that a variable gets assigned a value. That would be the value added to the parameter when the button is pressed to call the editing function (not written yet), but I wondered if it would be better not to do that until if the button was pressed, so it is incomplete.

C2:
I kept thinking there has to be an easier way...or at least one that reuses more code and is more efficient.

The code below cycles through all the menus. One function watches the encoder and calls LCDp(); to update the LCD cursor position. A third function writes the current full two line menu whenever needed.

void rollMenu() {

menu();
  LCD.print("?c2");                  // set cursor: 0=off, 2=underline, 1=highlight
  delay(100);
  LCDp();
  long newPosition = myEnc.read();
  oldPosition = newPosition;
  while (mode == 1) {
    long newPosition = myEnc.read();
    if (newPosition < oldPosition) {
      p--;
      if (p < 0) {
        p = 60;
      }
      LCDp();
    }
    if (newPosition > oldPosition) {
      p++;
      if (p > 60) {
        p = 0;
      }
      LCDp();
    }
    oldPosition = newPosition;
  }
}

void LCDp() {
  switch (p){
  case 0: // F0
    menu();
    LCD.print("?x03?y0");
    delta = 10000000;
    break;
  case 1:
    LCD.print("?x04?y0");
    delta = 1000000;
    break;
  case 2:
    LCD.print("?x05?y0");
    delta = 100000;
    break;
  case 3:
    LCD.print("?x06?y0");
    delta = 10000;
    break;
  case 4:
    LCD.print("?x07?y0");
    delta = 1000;
    break;
  case 5:
    LCD.print("?x08?y0");
    delta = 100;
    break;
  case 6:
    LCD.print("?x09?y0");
    delta = 10;
    break;
  case 7:
    LCD.print("?x10?y0");
    delta = 1;
    break;
  case 8: //P0
    LCD.print("?x04?y1");
    delta = 10;
    break;
  case 9:
    LCD.print("?x05?y1");
    delta = 1;
    break;
  case 10:
    menu();
    LCD.print("?x07?y1");
    delta = 0;
    break;   
  case 11: // F1
    menu();
    LCD.print("?x03?y0");
    break;
  case 12:
    LCD.print("?x04?y0");
    break;
  case 13:
    LCD.print("?x05?y0");
    break;
  case 14:
    LCD.print("?x06?y0");
    break;
  case 15:
    LCD.print("?x07?y0");
    break;
  case 16:
    LCD.print("?x08?y0");
    break;
  case 17:
    LCD.print("?x09?y0");
    break;
  case 18:
    LCD.print("?x10?y0");
    break;
  case 19:  // F2
    LCD.print("?x03?y1");
    break;
  case 20:
    LCD.print("?x04?y1");
    break;
  case 21:
    LCD.print("?x05?y1");
    break;
  case 22:
    LCD.print("?x06?y1");
    break;
  case 23:
    LCD.print("?x07?y1");
    break;
  case 24:
    LCD.print("?x08?y1");
    break;
  case 25:
    LCD.print("?x09?y1");
    break;
  case 26:
    menu();
    LCD.print("?x10?y1");
    break;
  case 27: // SWPTIME to DWLTIME
    menu();
    LCD.print("?x08?y0");
    break;
  case 28:
    LCD.print("?x09?y0");
    break;
  case 29:
    LCD.print("?x10?y0");
    break;
  case 30:
    LCD.print("?x11?y0");
    break;
  case 31:
    LCD.print("?x12?y0");
    break;
  case 32:
    LCD.print("?x13?y0");
    break;
  case 33:
    LCD.print("?x08?y1");
    break;
  case 34:
    LCD.print("?x09?y1");
    break;
  case 35:
    LCD.print("?x10?y1");
    break;
  case 36:
    LCD.print("?x11?y1");
    break;
  case 37:
    LCD.print("?x12?y1");
    break;
  case 38:
    menu();
    LCD.print("?x13?y1");
    break;
  case 39: // #STEPS
    menu();
    LCD.print("?x07?y0");
    break;
  case 40:
    LCD.print("?x08?y0");
    break;
  case 41:
    LCD.print("?x09?y0");
    break;
  case 42:
    LCD.print("?x10?y0");
    break;
  case 43:
    LCD.print("?x11?y0");
    break;
  case 44:
    LCD.print("?x12?y0");
    break;
  case 45:
    LCD.print("?x13?y0");
    break;
  case 46:
    LCD.print("?x14?y0");
    break;
  case 47: // SZ
    LCD.print("?x03?y1");
    break;
  case 48:
    LCD.print("?x04?y1");
    break;
  case 49:
    LCD.print("?x05?y1");
    break;
  case 50:
    LCD.print("?x06?y1");
    break;
  case 51:
    LCD.print("?x07?y1");
    break;
  case 52:
    LCD.print("?x08?y1");
    break;
  case 53:
    LCD.print("?x09?y1");
    break;
  case 54:
    menu();
    LCD.print("?x10?y1");
    break;
  case 55: // P1
    menu();
    LCD.print("?x04?y0");
    break;
  case 56:
    LCD.print("?x05?y0");
    break;
  case 57:
    LCD.print("?x07?y0");
    break;
  case 58: //P2
    LCD.print("?x04?y1");
    break;
  case 59:
    LCD.print("?x05?y1");
    break;
  case 60:
    menu();
    LCD.print("?x07?y1");
    break;
  }
}

void config() {
  mode = 1;
  menu();
}

void menu() {
  if (p >= 0 && p < 11) {
    LCD.print("?f");                   // clear the LCD
    LCD.print("?x00?y0");
    LCD.print("F0:");
    LCD.print(long(freq));
    LCD.print("?x14?y0");
    LCD.print("Hz");
    LCD.print("?x00?y1");
    LCD.print("P0: ");
    LCD.print("--.--");
    LCD.print("?x13?y1");
    LCD.print("dBm");
  }

if (p >= 11 && p < 27) {
    LCD.print("?f");                   // clear the LCD
    LCD.print("?x00?y0");
    LCD.print("F1:");
    LCD.print(long(F1));
    LCD.print("?x14?y0");
    LCD.print("Hz");
    LCD.print("?x00?y1");
    LCD.print("F2:");
    LCD.print(long(F2));
    LCD.print("?x14?y0");
    LCD.print("Hz");
  }

if (p >= 27 && p < 39) {
    LCD.print("?f");                   // clear the LCD
    LCD.print("?x00?y0");
    LCD.print("SWPTIME:");
    LCD.print(long(timeSweep));
    LCD.print("?x14?y0");
    LCD.print("us");
    LCD.print("?x00?y1");
    LCD.print("DWLTIME:");
    LCD.print(long(timeDwell));
    LCD.print("?x14?y1");
    LCD.print("us");
  }

if (p >= 39 && p < 55) {
    LCD.print("?f");                   // clear the LCD
    LCD.print("?x00?y0");
    LCD.print("#STEPS:");
    LCD.print(long(steps));
    LCD.print("?x00?y1");
    LCD.print("SZ:");
    LCD.print(long(fStep));
    LCD.print("?x14?y1");
    LCD.print("Hz");
  }

if (p >= 55 && p < 61) {
    LCD.print("?f");                   // clear the LCD
    LCD.print("?x00?y0");
    LCD.print("P1: ");
    LCD.print("--.--");
    LCD.print("?x13?y0");
    LCD.print("dBm");
    LCD.print("?x00?y1");
    LCD.print("P2: ");
    LCD.print("--.--");
    LCD.print("?x13?y1");
    LCD.print("dBm");
  }
}





You'll notice in the LCDp(); function that a variable gets assigned a value. That would be the value added to the parameter when the button is pressed to call the editing function (not written yet), but I wondered if it would be better not to do that until if the button was pressed, so it is incomplete.

Sorry - were you asking a question there ? or just generally throwing out the latest version of the code for interest ? (not being smart - just not sure)

Craig

The main question I had was if there is a better way to do it. Some of the smart folks here can take a hundred lines of code and reduce them to just three. Maybe in the end, bad code is just bad if it don't work. I did find an example of a two case switch case which might reduce the code slightly, but would still be the same logical approach.

Edit to add:

For example, positioning the LCD cursor might be better done in a loop with a counter rather than writing out each LCD.print command. It is harder for me to figure out in addition to the fact that the LCD takes string values rather than simpler numerical values [("?x00?y0") rather than (0,0)]. I bet there is a slick way to insert the correct numerical values into that string. Then I could use a counter and just send a generic command to the LCD to position the cursor (LCD.print("?x" && """ && xvar && """ && "?y" &""" && yvar && """))...