I2C 16x2 LCD Menus==1 sketch with 5 sketches

I have created a sketch which will hold 5 other sketches — I have been working on this for several years
and I wanted to share it with the world.

This is my initial Forum posting for this project. With kindness, offer up suggestions and post questions so I can create a useful video.

Thanks… Enjoy

DON’T use the code below. It is just to view the concept. The entire code is in the form
of an ATTACHMENT at the end.

/* by John Poston 7-22-2018
  

void setup() { //setup code put here to run once

  //Switch PinModes
  pinMode(swA, INPUT_PULLUP); //This method excludes the need for a pullup resistor on the switches
  pinMode(swB, INPUT_PULLUP);
  pinMode(swC, INPUT_PULLUP);
  //Motor pin declarations
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);


  //Declare LCD Object and size
  lcd.init();                      // initialize the lcd
  lcd.backlight();                 // Turn on the LCD Backlight
  testCode();   // Calls the function to verify upload transfer

}//Setup end bracket
//*************************************************LOOP************************************************************

void loop() { //loop code to run repeatedly

  mainMenu();   //Runs the menu selector for the number function to run
}
//**********************************************readSwitches*******************************************************
void readSwitches() { //Evaluates the States of the Two Switches
  swAval = digitalRead(swA);
  swBval = digitalRead(swB);
  swCval = digitalRead(swC);

}
//**********************************************read Potentiometer*************************************************
/*Reads the values of Potiometers on pins A0 and A1
   --then maps the ranges for A0 and A1
   --int a and b are the min/max range for A0
   --int c and d are the min/max range for A1*/

void potFunction(int a, int b, int c, int d) { //potFunction is looking for four intergers from the call
  potOne = analogRead (A0);   //Read A0
  potTwo = analogRead (A1);   //Read A1
  potOneVal = map(potOne, 0, 1023, a, b); //potOneVal int variable called by ranges a:min and b:max
  potTwoVal = map(potTwo, 0, 1023, c, d); //potTwoVal int variable called by ranges c:min and d:max
}
//  See EXAMPLE OF A 'potFunction' CALL at the end of this program

//************************************************mainMenu**********************************************************
void mainMenu() {
  potFunction(1,6,0,0);  //Syntax potFunction(potOneVal min, potOneVal Max, potTwoVal min, potTwoVal Max
  switch (potOneVal) {   //Pot One Value, 1 min and 6 max, for choosing cases 1 through 5 (zeros as null)
    //**************************************************************************************************************

    //==============================================CASES FOR MENU SELECTIONS=======================================
    case 1:

      lcd.home();                      //Bring cursor back to the beginning
      //       --1234567890123456--    //Lcd numbers for place holders
      lcd.print("#1   -Empty-    ");   //First Line of Each Sketch Name before Selected
      delay (tic);                     //Delay long enough for the lcd to refresh and display
      readSwitches();                  //Goes to the readSwitches function
      if (swAval == 0) {
        menuOne();                     //function chosen for this case selected by the variable resistor
      }                                //If swA is pressed, activate the function
      break;

    //================================================menuTwo=======================================================

    case 2:
      lcd.home();                      //Bring cursor back to the beginning
      //       --1234567890123456--    //Lcd numbers for place holders
      lcd.print("#2   -Empty-    ");   //First Line of Each Sketch Name before Selected
      delay (tic);                     //Delay long enough for the lcd to refresh and display
      readSwitches();                  //Goes to the readSwitches function
      if (swAval == 0) {
        menuTwo();                     //function chosen for this case selected by the variable resistor
      }                                //If swA is pressed, activate the function
      break;
    //================================================menuThree=====================================================

    case 3:
      lcd.home();                      //Bring cursor back to the beginning
      //       --1234567890123456--    //Lcd numbers for place holders
      lcd.print("#3   -Empty-    ");   //First Line of Each Sketch Name before Selected
      delay (tic);                     //Delay long enough for the lcd to refresh and display
      readSwitches();                  //Goes to the readSwitches function
      if (swAval == 0) {
        menuThree();                     //function chosen for this case selected by the variable resistor
      }                                //If swA is pressed, activate the function
      break;
    //================================================menuFour======================================================

    case 4:
      lcd.home();                      //Bring cursor back to the beginning
      //       --1234567890123456--    //Lcd numbers for place holders
      lcd.print("#4   -Empty-    ");   //First Line of Each Sketch Name before Selected
      delay (tic);                     //Delay long enough for the lcd to refresh and display
      readSwitches();                  //Goes to the readSwitches function
      if (swAval == 0) {
        menuFour();                    //function chosen for this case selected by the variable resistor
      }                                //If swA is pressed, activate the function
      break;
    //================================================menuFive======================================================

    case 5:
      lcd.home();                      //Bring cursor back to the beginning
      //       --1234567890123456--    //Lcd numbers for place holders
      lcd.print("#5   -Empty-    ");   //First Line of Each Sketch Name before Selected
      delay (tic);                     //Delay long enough for the lcd to refresh and display
      readSwitches();                  //Goes to the readSwitches function
      if (swAval == 0) {
        menuFive();                     //function chosen for this case selected by the variable resistor
      }                                //If swA is pressed, activate the function
      break;
      //==========================================================================================================

      //These brackets are only used at the end of the last case
  }//End of Switch Bracket
}//End of mainMenu function Bracket
//================================================================================================================


//=================================  Put SKETCHES in the function blocks below  ===================================

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//                                     --- menuOne Function Block ---
void menuOne() { //function bracket

  //****************This would be equivalent to the 'setup () {  }' area in a regular sketch **********************
  lcd.clear();
  lcd.setCursor(0, 0);
  //      --1234567890123456-- //Lcd numbers for place holders
  lcd.print("Program Run 1  ");
  lcd.setCursor(0, 1);
  //      --1234567890123456-- //Lcd numbers for place holders
  lcd.print("Program Running");


  //****************************************This would be the end of the setup area*********************************

  while (swBval == 1) { //While the B button is not pushed, do this until B is pushed

    //******************************** Equivalent to 'void loop () {  }' below**************************************



    //*************************************************End of menu chosen sketch************************************



    readSwitches();                      //Read the switch values in the readSwitches function



    if (swBval == 0) {                 //Look to see if swB is pressed
      lcd.clear();                     //if so, clear the lcd

      //*********************************************Do stuff here before 'return;' to Main Menu********************


      return;
    }//if swB is pressed Return
  }//While bracket
}//last function bracket

D_MENUS_5_Empty_7-22-2018.ino (16.4 KB)

Neatly written code but a couple of jpegs of the LCD under different conditions would help to understand what you have achieved. Keep up good work...

https://youtu.be/MNCHNpj9ruI