Menu Driven Program

Thank Mowcius!!

I have apadapted your code into my program and the mainmenu() sub is working.

I am having problems with the fillMenu() sub. Once I pick a delay time
it types the serial command the same amount of time (code highlighted below)

void mainMenu()
{ 
 //LCDclear();  //clears the LCD 
// Serial.println("Program Menu"); //prints to the lcd on first line -------------------------------------------------------------------------------------------> NOT NEEDED???
// LCDsecond(); //prints to lcd on second line etc... -------------------------------------------------------------------------------------------> NOT NEEDED???
 switch (programnumber) { //reads the program number (set as 1 in setup)
 case 1:            //displays the first menu item              
   Serial.println("Set Fill Delay");
   break;
 case 2:        //displays the second menu item
   Serial.println("Reset Fill Delay");
   break;
 case 3:       //displays the third menu item
   Serial.println("Ram Pulse");
   break;
 case 4:            //displays the first menu item              
   Serial.println("Start"); 
   break;
 case 5:        //displays the second menu item
   Serial.println("Pause");  
   break;
 case 6:       //displays the third menu item
   Serial.println("Stop");
   break;
 default:      //if errors then it goes to default item 
   Serial.println("Fill Delay");
}

 //Serial.println(0xFE, BYTE); //Command code-------------------------------------------------------------------------------------------> NOT NEEDED???
 //Serial.println(226, BYTE);  //Goes to specific point to display code-------------------------------------------------------------------------------------------> NOT NEEDED???
 Serial.println("Next >");    //next code in specific position 
 while(digitalRead(menuButton) == HIGH){} //while button is high do nothing: {} (helps with debounce after button has been pressed)
 delay(5);
 while(digitalRead(menuButton) == LOW){} //wait until button has been pressed (taken high).
   menudelaycount = 0; //clear menu delay
   while(menudelaycount <500){ //do this code within the 500 limit (over 500ms because of other stuff that is done and takes time)
   delay(1);
   menudelaycount++;
   if(digitalRead(menuButton) == LOW){ //if the button goes low (button released) within this loop then it advances one menu option
     programnumber++; //increase the menu option
   if(programnumber > 6){
     programnumber = 1;
   }
   mainMenu(); //then run menu code from start: the change in program number makes it change the option it is on.
   }
 }
 switch (programnumber) { //if the button is not let go within the menu time stated above then it does not loop back and then selects the subroutine from this switch case:
     case 1:
       Serial.println("Fill Func");
       fillMenu();
       break;
     case 2:
        Serial.println("Delay Func");
       break;
     case 3:
        Serial.println("Pulse Func");
       break;
      case 4:
        Serial.println("Start Func");
       break;
     case 5:
        Serial.println("Pause Func");
       break;
     case 6:
        Serial.println("Stop Func");
       break;
     default:
        Serial.println("Default Race");
     }
}

void fillMenu()
{ 
   FillDelay = FillDelay +3000;
   Serial.println(FillDelay);
   
   Serial.println("Next >");    
   while(digitalRead(menuButton) == HIGH){} 
     delay(5);
   while(digitalRead(menuButton) == LOW){} 
     menudelaycount = 0; 
   while(menudelaycount <500){ 
   delay(1);
   menudelaycount++;
   if(digitalRead(menuButton) == LOW){ 
     //programnumber++; 
   if(FillDelay > 120000){
     FillDelay = 0;
   }
   fillMenu(); 
  }
 }
   [glow]Serial.print("Fill Delay set @ ");
   Serial.print(FillDelay);[/glow]
}

Here is my Serial Output (I dont yet have my LCD some Im using Serial insted)

Set Fill Delay
Next >
Fill Func
4000
Next >
7000
Next >
Fill Delay set @ 7000Fill Delay set @ 7000Extending Ram
Holding Ram
Retracting Ram
Holding Ram

as you can see above I pressed the button twice and it prints the serial string twice. If i press the button 3 times it prints the serial string 3 times......

thanks again for all your help

Ben