Go Down

Topic: Still having problems with switch case menu... (Read 560 times) previous topic - next topic


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. :)  Thanks!

Code: [Select]
#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



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.setCursor(4, 0);

void loop()
 editSwitchState = digitalRead(editSwitchPin);

 switch (reflowState)
   lcd.setCursor(8, 0);
   if (editSwitchState == HIGH )
     reflowState = REFLOW_STATE_MENU_STEPS;

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

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

   if (okSwitchState == HIGH)
   if (cancelSwitchState == HIGH)
     reflowState = REFLOW_STATE_IDLE;



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


   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 ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.


Code: [Select]
if (editSwitchState == HIGH )
      reflowState = REFLOW_STATE_MENU_STEPS;

Same idea as here:


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 ?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.


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.


Go Up