Hi, I'm trying to use the bounce library and have a separate function to be called to read button presses.
My idea for the menu was to use case/switch statements to go from one part of the menu to the next using ok button to go to next menu state. This is my full sketch for this part. I'm using seperate sketches for different parts of my whole project then I'll add them together. I didn't add all the states. You'll see in code. I can't get past the first part so haven't coded past that. I wait too long to post then I'm in a rush to leave. I'm sorry if this isn't very clear.
#include <Bounce.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backlight = 13;
#define upSwitchPin 22
#define downSwitchPin 24
#define leftSwitchPin 26
#define rightSwitchPin 28
#define editSwitchPin 30
#define stopSwitchPin 32
#define okSwitchPin 34
byte buttonPressed;
Bounce upSwitchBounced = Bounce(upSwitchPin, 5);
Bounce downSwitchBounced = Bounce(downSwitchPin, 5);
Bounce leftSwitchBounced = Bounce(leftSwitchPin, 5);
Bounce rightSwitchBounced = Bounce(rightSwitchPin, 5);
Bounce editSwitchBounced = Bounce(editSwitchPin, 5);
Bounce stopSwitchBounced = Bounce(stopSwitchPin, 5);
Bounce okSwitchBounced = Bounce(okSwitchPin, 5);
byte currentProfile = 1;
byte profileSteps = 3;
byte profileEditStep = 1;
double rampRateStep1 = 1;
double rampRateStep2 = 1;
double rampRateStep3 = 1;
double rampRateStep4 = 1;
double rampRateStep5 = 1;
double rampRateStep6 = 1;
double rampRateStep7 = 1;
double rampRateStep8 = 1;
double rampRateStep9 = 1;
int dwellTimerStep1 = 30;
int dwellTimerStep2 = 30;
int dwellTimerStep3 = 30;
int dwellTimerStep4 = 30;
int dwellTimerStep5 = 30;
int dwellTimerStep6 = 30;
int dwellTimerStep7 = 30;
int dwellTimerStep8 = 30;
int dwellTimerStep9 = 30;
int temperatureStep1 = 120;
int temperatureStep2 = 180;
int temperatureStep3 = 225;
int temperatureStep4 = 150;
int temperatureStep5 = 130;
int temperatureStep6 = 150;
int temperatureStep7 = 170;
int temperatureStep8 = 190;
int temperatureStep9 = 220;
int Setpoint2 = 200;
typedef enum REFLOW_STATE
{
REFLOW_STATE_IDLE,
REFLOW_STATE_EDIT_MENU_BOTTOM_HEAT,
REFLOW_STATE_EDIT_MENU_STEP1,
REFLOW_STATE_EDIT_MENU_STEP1_RAMP,
REFLOW_STATE_EDIT_MENU_STEP1_TARGET,
REFLOW_STATE_EDIT_MENU_STEP1_DWELL,
REFLOW_STATE_EDIT_MENU_STEP2_RAMP,
REFLOW_STATE_EDIT_MENU_STEP2_TARGET,
REFLOW_STATE_EDIT_MENU_STEP2_DWELL,
REFLOW_STATE_EDIT_MENU_STEP3_RAMP,
REFLOW_STATE_EDIT_MENU_STEP3_TARGET,
REFLOW_STATE_EDIT_MENU_STEP3_DWELL,
REFLOW_STATE_EDIT_MENU_STEP4_RAMP,
REFLOW_STATE_EDIT_MENU_STEP4_TARGET,
REFLOW_STATE_EDIT_MENU_STEP4_DWELL,
REFLOW_STATE_EDIT_MENU_STEP5_RAMP,
REFLOW_STATE_EDIT_MENU_STEP5_TARGET,
REFLOW_STATE_EDIT_MENU_STEP5_DWELL,
REFLOW_STATE_EDIT_MENU_STEP6_RAMP,
REFLOW_STATE_EDIT_MENU_STEP6_TARGET,
REFLOW_STATE_EDIT_MENU_STEP6_DWELL,
REFLOW_STATE_EDIT_MENU_STEP7_RAMP,
REFLOW_STATE_EDIT_MENU_STEP7_TARGET,
REFLOW_STATE_EDIT_MENU_STEP7_DWELL,
REFLOW_STATE_EDIT_MENU_STEP8_RAMP,
REFLOW_STATE_EDIT_MENU_STEP8_TARGET,
REFLOW_STATE_EDIT_MENU_STEP8_DWELL,
REFLOW_STATE_EDIT_MENU_STEP9_RAMP,
REFLOW_STATE_EDIT_MENU_STEP9_TARGET,
REFLOW_STATE_EDIT_MENU_STEP9_DWELL,
REFLOW_STATE_EDIT_MENU_PEDIT,
REFLOW_STATE_EDIT_MENU_IEDIT,
REFLOW_STATE_EDIT_MENU_DEDIT,
} reflowState_t;
reflowState_t reflowState;
void buttonState(){
while ( upSwitchBounced.update()) { //need to read all buttons here
if (upSwitchBounced.read() == HIGH);
buttonPressed = 1; // variable to hold button pressed. How else could I do this?
if (downSwitchBounced.read() == HIGH);
buttonPressed = 2;
//add rest of buttons code here
}
}
void setup() {
pinMode(upSwitchPin, INPUT);
pinMode (downSwitchPin, INPUT);
pinMode (leftSwitchPin, INPUT);
pinMode (rightSwitchPin, INPUT);
pinMode (editSwitchPin, INPUT);
pinMode (stopSwitchPin, INPUT);
pinMode (okSwitchPin, INPUT);
lcd.begin(20, 4);
pinMode(backlight, OUTPUT);
digitalWrite(backlight, HIGH);
lcd.clear();
lcd.setCursor(8, 0);
lcd.print("IDLE");
}
void loop() {
reflowState = REFLOW_STATE_IDLE;
switch (reflowState)
{
case REFLOW_STATE_IDLE:
{
lcd.setCursor(8, 0);
lcd.print("IDLE");
buttonState();
if (buttonPressed == 1); {//not working goes straight to next state without button push
reflowState = REFLOW_STATE_EDIT_MENU_BOTTOM_HEAT;
}
break;
}
case REFLOW_STATE_EDIT_MENU_BOTTOM_HEAT:
{
lcd.setCursor(8, 0);
lcd.print(" ");
lcd.setCursor(3, 0);
lcd.print("Profile ");
lcd.print(currentProfile);
lcd.print(" Edit");
lcd.setCursor(2, 2);
lcd.print("Bottom Heat: ");
lcd.print(Setpoint2);
delay(200);
reflowState = REFLOW_STATE_EDIT_MENU_STEP1_RAMP;
}
}
}