Still having problems with switch case menu...

A few days ago I was experimenting with using software debouncing with a switch case lcd menu and wasn't getting anywhere even after a long time of working on it...
Instead of updating that thread I decided on going a different route for the menu hence the new one. Nothing else will be going on during menu so I decided to simply use delay() to compensate. Think that should work fine.

Anyways, I'm working on this menu. Still in the beginning stages. I just can't for the life of me figure out why this isn't working how I have it coded. Keep in mind I'm a total noob. I tried using arrays and couldn't get them to work so code looks sloppy etc. If it would just work I'd be happy about now.

Whats happening here is when the sketch starts IDLE shows up on the LCD. When edit switch is pressed MENU_STATE_STEPS starts up just fine but it gets stuck there. I used the same type of code to check if up/down buttons are pressed as well as cancel and run. Whats happening though is from IDLE it goes to the next state which is MENU_STATE_STEPS just fine but won't do anything after that with button presses. Anyone have any idea whats going on?

I haven't added any delay statements yet since I haven't needed to. Some help would be greatly appreciated. :slight_smile: Thanks!

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backlight = 13;
int upSwitchPin = 22;
int downSwitchPin = 24;
int leftSwitchPin = 26;
int rightSwitchPin = 28;
int editSwitchPin = 30;
int cancelSwitchPin = 32;
int okSwitchPin = 34;

int upSwitchState = 0;
int downSwitchState = 0;
int leftSwitchState = 0;
int rightSwitchState = 0;
int editSwitchState = 0;
int cancelSwitchState = 0;
int okSwitchState = 0;

byte currentProfile = 1;
byte profileSteps = 3;
byte profileEditStep = 1;
int Setpoint2 = 200;




// ***** TYPE DEFINITIONS *****
typedef enum REFLOW_STATE
{
  REFLOW_STATE_IDLE,
  REFLOW_STATE_MENU_STEPS,
  REFLOW_STATE_MENU_BOTTOM_HEAT,
  REFLOW_STATE_MENU_BOTTOM_P,
  REFLOW_STATE_MENU_BOTTOM_I,
  REFLOW_STATE_MENU_BOTTOM_D,
  REFLOW_STATE_MENU_STEP_1_RAMP,
  REFLOW_STATE_MENU_STEP_1_TARGET,
  REFLOW_STATE_MENU_STEP_1_DWELL,
  REFLOW_STATE_MENU_STEP_2_RAMP,
  REFLOW_STATE_MENU_STEP_2_TARGET,
  REFLOW_STATE_MENU_STEP_2_DWELL,
  REFLOW_STATE_MENU_STEP_3_RAMP,
  REFLOW_STATE_MENU_STEP_3_TARGET,
  REFLOW_STATE_MENU_STEP_3_DWELL,
  REFLOW_STATE_MENU_STEP_4_RAMP,
  REFLOW_STATE_MENU_STEP_4_TARGET,
  REFLOW_STATE_MENU_STEP_4_DWELL,
  REFLOW_STATE_MENU_STEP_5_RAMP,
  REFLOW_STATE_MENU_STEP_5_TARGET,
  REFLOW_STATE_MENU_STEP_5_DWELL,
  REFLOW_STATE_MENU_STEP_6_RAMP,
  REFLOW_STATE_MENU_STEP_6_TARGET,
  REFLOW_STATE_MENU_STEP_6_DWELL,
  REFLOW_STATE_MENU_STEP_7_RAMP,
  REFLOW_STATE_MENU_STEP_7_TARGET,
  REFLOW_STATE_MENU_STEP_7_DWELL,
  REFLOW_STATE_MENU_STEP_8_RAMP,
  REFLOW_STATE_MENU_STEP_8_TARGET,
  REFLOW_STATE_MENU_STEP_8_DWELL,
  REFLOW_STATE_MENU_STEP_9_RAMP,
  REFLOW_STATE_MENU_STEP_9_TARGET,
  REFLOW_STATE_MENU_STEP_9_DWELL,
  REFLOW_STATE_MENU_TOP_P,
  REFLOW_STATE_MENU_TOP_I,
  REFLOW_STATE_MENU_TOP_D,

  REFLOW_STATE_STEP_1_RAMP, 
  REFLOW_STATE_STEP_1,
  REFLOW_STATE_STEP_1_DWELL,
  REFLOW_STATE_STEP_2_RAMP,
  REFLOW_STATE_STEP_2,
  REFLOW_STATE_STEP_2_DWELL,
  REFLOW_STATE_STEP_3_RAMP,
  REFLOW_STATE_STEP_3,
  REFLOW_STATE_STEP_3_DWELL,  
  REFLOW_STATE_STEP_4_RAMP,
  REFLOW_STATE_STEP_4,
  REFLOW_STATE_STEP_4_DWELL,
  REFLOW_STATE_STEP_5_RAMP,
  REFLOW_STATE_STEP_5,
  REFLOW_STATE_STEP_5_DWELL,
  REFLOW_STATE_STEP_6_RAMP,
  REFLOW_STATE_STEP_6,
  REFLOW_STATE_STEP_6_DWELL,
  REFLOW_STATE_STEP_7_RAMP,
  REFLOW_STATE_STEP_7,
  REFLOW_STATE_STEP_7_DWELL,
  REFLOW_STATE_STEP_8_RAMP,
  REFLOW_STATE_STEP_8,
  REFLOW_STATE_STEP_8_DWELL,
  REFLOW_STATE_STEP_9_RAMP,
  REFLOW_STATE_STEP_9,
  REFLOW_STATE_STEP_9_DWELL,
  REFLOW_STATE_COMPLETE,
  REFLOW_STATE_ERROR


} 
reflowState_t;

reflowState_t reflowState;


void setup()
{
  pinMode (upSwitchPin, INPUT);
  pinMode (downSwitchPin, INPUT);
  pinMode (leftSwitchPin, INPUT);
  pinMode (rightSwitchPin, INPUT);
  pinMode (editSwitchPin, INPUT);
  pinMode (cancelSwitchPin, INPUT);
  pinMode (okSwitchPin, INPUT);
  pinMode (backlight, OUTPUT);
  digitalWrite(backlight, HIGH);
  lcd.begin(20, 4);
  lcd.clear();
  lcd.setCursor(4, 0);

}
void loop()
{
  editSwitchState = digitalRead(editSwitchPin);


  switch (reflowState)
  {
  case REFLOW_STATE_IDLE:
    lcd.setCursor(8, 0);
    lcd.print("IDLE");
    if (editSwitchState == HIGH ) 
    {
      reflowState = REFLOW_STATE_MENU_STEPS;
    }
    break;  
  case REFLOW_STATE_MENU_STEPS:

    lcd.setCursor(3, 0);
    lcd.print("Profile ");
    lcd.print(currentProfile);
    lcd.print(" Edit");
    lcd.setCursor(2, 2);
    lcd.print("Profile Steps: ");
    lcd.print(profileSteps);

    if (upSwitchState == HIGH)
    {
      profileSteps = profileSteps + 1;
    }
    if (downSwitchState == HIGH)
    {
      profileSteps = profileSteps - 1;
    }

    if (okSwitchState == HIGH)
    {
      reflowState = REFLOW_STATE_MENU_BOTTOM_HEAT;
    }
    if (cancelSwitchState == HIGH)
    {
      reflowState = REFLOW_STATE_IDLE;
    }

    break;

  case REFLOW_STATE_MENU_BOTTOM_HEAT:

    lcd.setCursor(2, 2);
    lcd.print("                  ");
    lcd.setCursor(1, 2);
    lcd.print("Bottom Heat: ");
    lcd.print(Setpoint2);

    break;

  case REFLOW_STATE_MENU_BOTTOM_P:
    lcd.setCursor(2, 2);
    lcd.print("                   ");
    lcd.setCursor(1, 2);
    lcd.print("Bottom Heater P=");


  }
}

Where in the code are you reading the pins to get the values of upSwitchState, downSwitchState and okSwitchState ?

if (editSwitchState == HIGH ) 
    {
      reflowState = REFLOW_STATE_MENU_STEPS;
    }

Same idea as here:

http://arduino.cc/en/tutorial/button

I'm not really clear on how to stay in the 'state' and not change 'state' at all until OK button is pressed either. I thought that without the 'break' statement that it would be stuck in the current state but no workie.

Where in the code are you reading the pins to get the values of upSwitchState, downSwitchState and okSwitchState ?

OMG guys. Yeah thanks! I have no clue how that happened lol. Another case of need to take a break... I set all those variables that hold the button state but was changing between different versions of my sketch and must have forgotten to set them on this one. Even after looking at it geeze. I actually remember now.. I was just trying to get edit to work on one first etc.

THANKS!

Glad you found it.
It's the sort of bug that serial prints (which could be removed later) would have found.

Good call and thanks again. Its working perfectly. Will keep that in mind!