LCD menu options (best route)

switch (lightMode) {
    case 0: lightMode = 1; break;
    case 1: lightMode = 2; break;
    case 2: lightMode = 3; break;
    case 3: lightMode = 4; break;
    case 4: lightMode = 5; break;
    case 5: lightMode = 0; break;
}

or even more succinct:

lightMode = (lightMode + 1) % 6;

OK, I got it to actually do something. However, I am not sure how to implement the button, so it is not waiting for a button push. It is simply looping through the LED menu. I am assuming an "if" statement of some sort within each case?

Here is the revised code.

Thanks for your helpfulness. It means a lot!!

 /*
   LCD portion of the code. Sets up the pins
   and intro screen.
  
  The circuit:
  * LCD RS pin to digital pin 2
  * LCD Enable pin to digital pin 3
  * LCD D4 pin to digital pin 4
  * LCD D5 pin to digital pin 5
  * LCD D6 pin to digital pin 6
  * LCD D7 pin to digital pin 7
  * 10K resistor:
    * ends to +5V and ground
    * wiper to LCD VO pin (pin 3)
  
  http://www.arduino.cc/en/Tutorial/LiquidCrystal
  
  */

 // include the library code:
 #include 

 // initialize the 4 bit LCD library with the numbers of the interface pins
 LiquidCrystal lcd(2, 3, 4, 5, 6, 7);


 // set pin numbers:


int switchPin1 =12;              // switch1 is connected to pin 12
int switchPin2 =11;              // switch2 is connected to pin 11
int switchPin3 =10;              // switch3 is connected to pin 10
int switchPin4 =9;              // switch4 is connected to pin 9
int switchPin5 =8;              // switch5 is connected to pin 8

int led1Pin = 13;
int led2Pin = 8;
int led3Pin = 9;
int led4Pin = 10;
int led5Pin = 1;

int val;                        // variable for reading the pin status
int val2;                       // variable for reading the delayed status
int buttonState;                // variable to hold the button state

int lightMode;                 // What mode is the light in?



//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 

 void setup() {
   
   //LCD SETUP
   
   // set up the LCD's number of rows and columns: 
   lcd.begin(16, 2);
   
   // Print a message to the LCD.
   lcd.print("**MIDI NIGHTS**");
   delay (1000);
   lcd.setCursor(0, 4);
   lcd.print("LED Menu Options");
   delay (1000);
   lcd.clear();
     
     // resets cursor position 
   lcd.setCursor(0, 4); 
   lcd.print("    Use right/left buttons to select LED    ");
   delay (20);
   
     // scroll 150 positions (string length) to the left 
     // to move it offscreen left:
  for (int positionCounter = 0; positionCounter < 27; positionCounter++) {
     // scroll one position left:
    lcd.scrollDisplayLeft(); 
     // wait a bit:
    delay(50);
  }
  lcd.clear();    //clear screen and reset cursor
  lcd.setCursor(1, 9);
  lcd.print("Select LED < >");  //Select desired LED
  delay (4000);    // delays on this screen then goes to led choices
  
  //BUTTON SETUP
  
  pinMode(switchPin1, INPUT);    // Set the switch pin as input for menu right
  pinMode(switchPin2, INPUT);    // Set the switch pin as input for menu left
  pinMode(switchPin3, INPUT);    // Set the switch pin as input for menu up
  pinMode(switchPin4, INPUT);    // Set the switch pin as input for menu down
  pinMode(switchPin5, INPUT);    // Set the switch pin as input for menu store

  pinMode(led1Pin, OUTPUT);     // leds outputs that will eventually become the LEDs 1-33 (11 LED selections with three colors each)
  pinMode(led2Pin, OUTPUT);     // right now they each button press lights up the same light
  pinMode(led3Pin, OUTPUT);     // ultimate goal is to charlieplex with decoder and latches
  pinMode(led4Pin, OUTPUT);
  pinMode(led5Pin, OUTPUT);
  
  Serial.begin(9600);           // Set up serial communication at 9600bps
  buttonState = digitalRead(switchPin1);   // read the initial state
}


//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 void loop() {

switch (lightMode){
                                    // Now do whatever the lightMode indicates
  case 0: lightMode = 1;  
    digitalWrite(led1Pin, HIGH);
    lcd.clear();
    lcd.print("LED 1");
    delay (100);
    break;


  case 1: lightMode = 2;            
    digitalWrite(led1Pin, HIGH);    //turns on LED
    lcd.clear();                    // clears screen
    lcd.print("LED 2");             // name of led
    delay (100);                    // delay to keep the lCD from flashing so much while looping, not exactly what I am after
    break; 
  

  case 2: lightMode = 3;  
    digitalWrite(led1Pin, HIGH);
    lcd.clear();
    lcd.print("LED 3");
    delay (100);
    break;
  
  case 3: lightMode = 4;   
    digitalWrite(led1Pin, HIGH);
    lcd.clear();
    lcd.print("LED 4");
    delay (100);
    break;
  
  case 4: lightMode = 5;   
    digitalWrite(led1Pin, HIGH);
    lcd.clear();
    lcd.print("LED 5");
    delay (100);
    break;
  
  case 5: lightMode = 6;  
    digitalWrite(led1Pin, HIGH);
    lcd.clear();
    lcd.print("LED 6");
    delay (100);

  case 6: lightMode = 0; 
  break;
  }
}

Wow, that was brutal, but I finally got a switch case situation to work. I believe I can start actually coding something now! ::)

Here is the very basic code:

 // include the library code:
 #include 

 // initialize the 4 bit LCD library with the numbers of the interface pins
 LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

//first define states with obvious names and different values
#define START 0
#define RED 1
#define BLUE 2
//next define which pin is which
#define RED_PIN 9
#define BLUE_PIN 10


int buttonState = 0; 
int switchPin = 11;              // switch is connected to pin 2
int val;                        // variable for reading the pin status
int val2;
int lightMode = 0;              // What mode is the light in?
int state = START; //create state variable and initialize it to START state

  
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
void setup() {
   
   //LCD SETUP
   
   // set up the LCD's number of rows and columns: 
   lcd.begin(16, 2);
   
   // Print a message to the LCD.
   
   lcd.print("**MIDI NIGHTS**");
   delay (1000);
   lcd.setCursor(0, 4);
   lcd.print("LED Menu Options");
   delay (1000);
   lcd.clear();
     
     // resets cursor position 
   lcd.setCursor(0, 4); 
   lcd.print("    Use right/left buttons to select LED    ");
   delay (20);
   
     // scroll 150 positions (string length) to the left 
     // to move it offscreen left:
    for (int positionCounter = 0; positionCounter < 27; positionCounter++) {
     // scroll one position left:
    lcd.scrollDisplayLeft(); 
     // wait a bit:
    delay(50);
    }
{
  delay (300);
  lcd.clear();    //clear screen and reset cursor
  lcd.setCursor(1, 9);
  lcd.print("Select LED < >");  //Select desired LED
  delay(2000);
} 
pinMode(RED_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
digitalWrite(BLUE_PIN,LOW); //turn blue led off
digitalWrite(RED_PIN,LOW); //turn red led off
pinMode(switchPin, INPUT);    // Set the switch pin as input


Serial.begin(9600);           // Set up serial communication at 9600bps

}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


void loop(){
buttonState = digitalRead(switchPin);
  
  if (buttonState == LOW){
    }
 else {
  //FSM time
switch(state){
case START:
    lcd.clear();
    lcd.print("Snare");
    digitalWrite(BLUE_PIN,LOW); //turn blue led off
    digitalWrite(RED_PIN,LOW); //turn red led off
    delay(100); //wait 100ms
    state = RED; //transition to red state
    break; //end of START case
  case RED:
    lcd.clear();
    lcd.print("TOM1");
    digitalWrite(BLUE_PIN,LOW); //turn blue led off
    digitalWrite(RED_PIN,HIGH); //turn red led on
    delay(200); //wait 200ms
    state = BLUE; //transition to blue state
    break; //end of RED case
  case BLUE:
    lcd.clear();
    lcd.print("TOM2");
    digitalWrite(RED_PIN,LOW); //turn red led off
    digitalWrite(BLUE_PIN,HIGH); //turn blue led on
    delay(200); //wait 200ms
    state = START; //transition to start state
    break; //end of BLUE case
  }
}
}

You have this:

  if (buttonState == LOW){
    }
 else {

Why not simply:

if(buttonState == HIGH){

Ha Ha, yep that works too. Thanks! 8-)

I am now trying to nest a second switch/case into the first case "Start" and I a can't get any reaction from it. I think I have some of the {} in the wrong places. Any thoughts?

#include 

 // include the library code:
 #include 

 // initialize the 4 bit LCD library with the numbers of the interface pins
 LiquidCrystal lcd(2, 3, 4, 5, 6, 7);

//first define states with obvious names and different values
#define START 0
#define RED 1
#define BLUE 2
#define START2 0
#define RED2 1
#define BLUE2 2
//next define which pin is which
#define RED_PIN 9
#define BLUE_PIN 10


int buttonState = 0;
int buttonState2 = 0;
int switchPin = 11;              // switch is connected to pin 11
int switchPin2 = 12;            // switch is connected to pin 12

int state = START; //create state variable and initialize it to START state
int state2 = START2; //create state variable and initialize it to START state

  
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
void setup() {
   
   //LCD SETUP
   
   // set up the LCD's number of rows and columns: 
   lcd.begin(16, 2);
   
   // Print a message to the LCD.
   
   lcd.print("**MIDI NIGHTS**");
   delay (1000);
   lcd.setCursor(0, 4);
   lcd.print("LED Menu Options");
   delay (1000);
   lcd.clear();
     
     // resets cursor position 
   lcd.setCursor(0, 4); 
   lcd.print("    Use right/left buttons to select LED    ");
   delay (20);
   
     // scroll 150 positions (string length) to the left 
     // to move it offscreen left:
    for (int positionCounter = 0; positionCounter < 27; positionCounter++) {
     // scroll one position left:
    lcd.scrollDisplayLeft(); 
     // wait a bit:
    delay(50);
    }
{
  delay (300);
  lcd.clear();    //clear screen and reset cursor
  lcd.setCursor(1, 9);
  lcd.print("Select LED < >");  //Select desired LED
  delay(2000);
} 
pinMode(RED_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
digitalWrite(BLUE_PIN,LOW); //turn blue led off
digitalWrite(RED_PIN,LOW); //turn red led off
pinMode(switchPin, INPUT);    // Set the switch pin as input
pinMode(switchPin2, INPUT);    // Set the switch pin as input

Serial.begin(9600);           // Set up serial communication at 9600bps

}

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


void loop(){
buttonState = digitalRead(switchPin);
buttonState2 = digitalRead(switchPin2);

  if (buttonState == HIGH){
  //FSM time
switch(state){
case START:
    lcd.clear();
    lcd.print("Snare");
    digitalWrite(BLUE_PIN,LOW); //turn blue led off
    digitalWrite(RED_PIN,LOW); //turn red led off
    delay(100); //wait 100ms

                    
          if (buttonState2 == HIGH) 
        switch(state2){
            case START2:
                lcd.clear();
                lcd.print("Color 1");
                state2 = RED2; //transition to red state
                break; //end of START case
            case RED2:
                lcd.clear();
                lcd.print("Color 2");
                state2 = BLUE2; //transition to blue state
                break; //end of RED case
            case BLUE2:
                lcd.clear();
                lcd.print("Color 3");
                state2 = START2; //transition to start state
                break; //end of BLUE case
        }
    state = RED; //transition to red state    
    break; //end of START case               
  

    
  case RED:
    lcd.clear();
    lcd.print("TOM1");
    digitalWrite(BLUE_PIN,LOW); //turn blue led off
    digitalWrite(RED_PIN,HIGH); //turn red led on
    delay(200); //wait 200ms
    state = BLUE; //transition to blue state
    break; //end of RED case
  case BLUE:
    lcd.clear();
    lcd.print("TOM2");
    digitalWrite(RED_PIN,LOW); //turn red led off
    digitalWrite(BLUE_PIN,HIGH); //turn blue led on
    delay(200); //wait 200ms
    state = START; //transition to start state
    break; //end of BLUE case
  }
}
}
if (buttonState2 == HIGH)
[glow]{
[/glow]        switch(state2){
            case START2:
                lcd.clear();
                lcd.print("Color 1");
                state2 = RED2; //transition to red state
                break; //end of START case
            case RED2:
                lcd.clear();
                lcd.print("Color 2");
                state2 = BLUE2; //transition to blue state
                break; //end of RED case
            case BLUE2:
                lcd.clear();
                lcd.print("Color 3");
                state2 = START2; //transition to start state
                break; //end of BLUE case
        }
[glow]}[/glow]

I tried that, but nothing changed. Any other ideas or possible errors in my code?

Thank you for looking at this for my PaulS!

The code, as you have it written, requires that you have both buttons pressed. Do you?

No, I wasn't. I guess I need to change "buttonState" back to low before I can use "buttonState2" by itself?

I tried that, but nothing changed

That's because they're not required.

Is there another way I can write "buttonState" at the beginning of the loop so that I can bring it back to LOW during the second switch/case?

What you could do is move the button 2 code after the end of the button 1 switch statement, and execute the code if state == RED.

Hope you guys aren't getting sick of me yet. I really appreciate your time and input. I am learning as I go and wearing my google button out! ::)

Here is how I tried to implement your idea PaulS. I still get no entry into the second switch/case. I changed up some of the variable names to make more sense with the project. I hope that doesn't throw too much confusion into the mix.

If I can get this last issue, then maybe I can leave you guys alone for awhile! :D

void loop(){
  buttonState = digitalRead(switchPin);
  buttonState2 = digitalRead(switchPin2);

  if (buttonState == HIGH){
    switch(ledstate){
    case LED1:
      lcd.clear();
      lcd.print("Snare");
      digitalWrite(BLUE_PIN,HIGH); //turn blue led off
      digitalWrite(RED_PIN,HIGH); //turn red led off
      delay(100); //wait 100ms
      ledstate = LED2; //transition to red state    
      break; //end of START case               

    case LED2:
      lcd.clear();
      lcd.print("TOM 1");
      digitalWrite(BLUE_PIN,LOW); //turn blue led off
      digitalWrite(RED_PIN,HIGH); //turn red led on
      delay(200); //wait 200ms
      ledstate = LED3; //transition to blue state
      break; //end of RED case

    case LED3:
      lcd.clear();
      lcd.print("TOM 2");
      digitalWrite(RED_PIN,LOW); //turn red led off
      digitalWrite(BLUE_PIN,HIGH); //turn blue led on
      delay(200); //wait 200ms
      ledstate = LED1; //transition to start state
      break; //end of BLUE case
    }

    {
      if (ledstate == LED2)
        if (buttonState2 == HIGH)
          if (buttonState == LOW){
            switch(colorState){
            case COLOR1:
              lcd.clear();
              lcd.print("Color 1");
              colorState = COLOR2; //transition to red state
              break; //end of START case
            case COLOR2:
              lcd.clear();
              lcd.print("Color 2");
              colorState = COLOR3; //transition to blue state
              break; //end of RED case
            case COLOR3:
              lcd.clear();
              lcd.print("Color 3");
              colorState = COLOR1; //transition to start state
              break; //end of BLUE case
            }
          }

    }
  }
}

This:

      if (ledstate == LED2)
        if (buttonState2 == HIGH)
          if (buttonState == LOW){

is the same as writing:

      if  ( (ledstate == LED2) &&
            (buttonState2 == HIGH) && 
            (buttonState == LOW)) {

OK, but will that change anything to make it work?

No, but it may make it easier to read.

OK :)

Is it safe to assume that you pushed button 1, and then pushed button 2?

Yes and although you were correct in that, It is definitely not what I am after. I tried moving it outside of the case, but think it is still expecting a "high" on button one to make it function when ledstate == led2

I made some changes to the variable names as I mentioned.

You aren't debouncing the buttons, or toggling behavior only when the button state changes.

Your behavior is based on the button state being HIGH.

This is fine if you want something to happen while a button is pressed, like a doorbell ringing. It's not fine, if you want to implement a state machine, as you are (trying to).

You need to keep track of the previous state of the buttons, and only act when the state changes:

int previousButtonOneState = LOW;
int previousButtonTwoState = LOW;

void loop()
{
   int buttonOneState = digitalRead(buttonOnePin);
   int buttonTwoState = digitalRead(buttonTwoPin);

   if(buttonOneState == HIGH && previousButtonOneState == LOW)
   {
       // Button One was just pushed. Make the state changes...
   }
   previousButtonOneState = buttonOneState;

   if(buttonTwoState == HIGH && previousButtonTwoState == LOW)
   {
       // Button Two was just pushed. Now, we can rely on the state
   }
   previousButtonTwoState = buttonTwoState;
}