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!
#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=");
}
}