Several switch cases are skipped when LCD menu is run

Hi all,

I’m currently trying to design my own menu system using switch cases and an lcd I2C. First I created a code which first runs the LAYER_SELECT case, enters the MODE_SELECT case after, ad from there enters SPRAY or DIP depending on which buttons are pressed. Then i added SPRAY_ZERO, "FIVE, "TEN which are all variations on the same code but with some for loops that run longer (I don’t think this affects my problem, however the bool leftRightSpray/Dip names might have something to do with it?).

What i’m trying to do is move from the mode select case to the SPRAY_MODE case from which the 3 spray variations can be accessed. Essentially its a menu with a submenu with a submenu (if that makes sense). The selections are governed by button ISRs found at the bottom of the code.

On attempting to add these new spray cases i have found that the code skips straight from the mode select to SPRAY_TEN when button A) is pressed in the mode select loop. Can you explain why this is happening? Is it a problem with my case definitions, enums or something else? I’m fairly new to switch cases so any lessons for use in future would be very helpful too!

The buttons are pull down resistor governed. Had to delete some code due to character restrictions so is very messy, sorry. Tried to keep main (ie problematic) bit clear.

Thanks in advance! Pls educate me

#include <Wire.h>

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

#define UP_BUTTON 18
#define DOWN_BUTTON 3
#define SELECT_BUTTON 2

*/
enum State
{
  LAYER_SELECT,
  MODE_SELECT,
  SPRAY_MODE,
  SPRAY_ZERO,
  SPRAY_FIVE,
  SPRAY_TEN,
  DIP
};


// Variables will change:

bool leftRightDip = true;
bool leftRightSprayZ = true;
bool leftRightSprayF = true;
bool leftRightSprayT = true;

//buttons and interface
int upButtonState = 0;         // current state of the button
int downButtonState = 0;         // current state of the button
int selectButtonState = 0;
int lastButtonState = 0;     // previous state of the button
volatile unsigned long debounceTimer = 0;
int buttonPushCounter = 0;   // counter for the number of button presses
bool select = false;
int layers = 0;
State state = LAYER_SELECT;



void setup() {

  //buttons
  pinMode(UP_BUTTON, INPUT);
  pinMode(DOWN_BUTTON, INPUT);
  pinMode(SELECT_BUTTON, INPUT);
  pinMode(LED_BUILTIN, OUTPUT);

  attachInterrupt(digitalPinToInterrupt(UP_BUTTON), UP_BUTTON_ISR, RISING);
  attachInterrupt(digitalPinToInterrupt(DOWN_BUTTON), DOWN_BUTTON_ISR, RISING);
  attachInterrupt(digitalPinToInterrupt(SELECT_BUTTON), SELECT_BUTTON_ISR, RISING);


  lcd.begin();

  Serial.begin(9600);
}


void loop()
{
  switch (state)
  {
    case LAYER_SELECT:
      layerSelect();
      break;

    case MODE_SELECT:
      modeSelect();
      break;

    case SPRAY_MODE:
      sprayMode();
      break;

    case SPRAY_ZERO:
      sprayZero();
      break;

    case SPRAY_FIVE:
      sprayFive();
      break;

    case SPRAY_TEN:
      sprayTen();
      break;

    case DIP:
      dip();
      break;
  }
}

void layerSelect()
{
  if (buttonPushCounter < 0)
  {
    buttonPushCounter = 0;
  }

  lcd.setCursor(0, 0);
  lcd.print("Layer Number:");
  lcd.setCursor(14, 0);
  lcd.print(String(buttonPushCounter) + " ");
  lcd.setCursor(0, 1);
  lcd.print("A)Up(B)Down(C)Ok");

  if (select)
  {
    layers = buttonPushCounter;
    state = MODE_SELECT;
    buttonPushCounter = 0;
    select = false;
    lcd.clear();
    delay(100);
  }
}

void modeSelect()
{
  lcd.setCursor(2, 0);
  lcd.print("Choose Mode:");
  lcd.setCursor(0, 1);
  lcd.print("(A)Spray");
  lcd.setCursor(10, 1);
  lcd.print("(B)Dip");

  if (buttonPushCounter >= 1)
  {
    state = SPRAY_MODE;
    buttonPushCounter = 0;
    select = false;
    lcd.clear();
    delay(100);
  }
  else if (buttonPushCounter <= -1)
  {
    state = DIP;
    buttonPushCounter = 0;
    select = false;
    lcd.clear();
    delay(100);
  }
}

void sprayMode()
{
  lcd.setCursor(2, 0);
  lcd.print("Spray Time /Secs:");
  lcd.setCursor(0, 1);
  lcd.print("(A)0");
  lcd.setCursor(5, 1);
  lcd.print("(B)5");
  lcd.setCursor(11, 1);
  lcd.print("(C)10");

  if (buttonPushCounter >= 1)
  {
    state = SPRAY_ZERO;
    buttonPushCounter = 0;
    select = false;
    lcd.clear();
    delay(100);
  }
  else if (buttonPushCounter <= -1)
  {
    state = SPRAY_FIVE;
    buttonPushCounter = 0;
    select = false;
    lcd.clear();
    delay(100);
  }
  else if (select = true)
  {
    state = SPRAY_TEN;
    buttonPushCounter = 0;
    select = false;
    lcd.clear();
    delay(100);
  }
}


//spray and dip void functions
void dip()
{
  if (layers == 0)
  {
    state = LAYER_SELECT;
    buttonPushCounter = 0;
    select = false;
    lcd.clear();
    delay(100);
    return;
  }
   lcd.print ("Running Dip");
  diptest (leftRightDip);
  leftRightDip = ! leftRightDip;

  layers--;
}

void sprayZero()
{
  if (layers == 0)
  {
    state = LAYER_SELECT;
    buttonPushCounter = 0;
    select = false;
    lcd.clear();
    delay(100);
    return;
  }

  lcd.print ("Spray 0 Sec");
  SprayTestZero (leftRightSprayZ);      //might need to alter the bool name for each spray number- CHECK!!!
  leftRightSprayZ = ! leftRightSprayZ;

  layers--;
}

void sprayFive()
{
  if (layers == 0)
  {
    state = LAYER_SELECT;
    buttonPushCounter = 0;
    select = false;
    lcd.clear();
    delay(100);
    return;
  }
   lcd.print ("Spray 5 Sec");
  SprayTestFive (leftRightSprayF);      //might need to alter the bool name for each spray number- CHECK!!!
  leftRightSprayF = ! leftRightSprayF;

  layers--;
}

void sprayTen()
{
  if (layers == 0)
  {
    state = LAYER_SELECT;
    buttonPushCounter = 0;
    select = false;
    lcd.clear();
    delay(100);
    return;
  }
  lcd.print ("Spray 10 Sec");
  SprayTestTen (leftRightSprayT);      //might need to alter the bool name for each spray number- CHECK!!!
  leftRightSprayT = ! leftRightSprayT;

  layers--;
}

void SprayTestZero (bool leftRightSprayZ) {

  if (SprayTestZero == true) {

    anticlockwise90();
    delay(5000);
    for (int x = 0; x < 18; x++) //x will be lower and we'll need to slow the descent and number of steps will need to be smaller, so separate dipdown and dipup function
    {
      dipdown();
    }
    
}

void SprayTestFive (bool leftRightSprayF) {

  if (SprayTestFive == true) {

    anticlockwise90();
    delay(5000);
    for (int x = 0; x < 18; x++) //x will be lower and we'll need to slow the descent and number of steps will need to be smaller, so separate dipdown and dipup function
    {
      dipdown();
    }
    delay(5000);
   
}

void SprayTestTen (bool leftRightSprayT) {

  if (SprayTestTen == true) {

    anticlockwise90();
    delay(5000);
    for (int x = 0; x < 18; x++) //x will be lower and we'll need to slow the descent and number of steps will need to be smaller, so separate dipdown and dipup function
    {
      dipdown();
    }
    delay(5000);
   
}

//Dip testing
void diptest(bool leftRightDip) {

  if (diptest == true)
  {
    anticlockwise90();
    delay(5000);
    for (int x = 0; x < 18; x++)
    {
      delay(2000);
      dipdown();
 
}

//Spray testing- with wash
void spraytest (bool leftRightSpray) {

  if (spraytest == true) {

    anticlockwise90();
    delay(5000);
    for (int x = 0; x < 18; x++) //x will be lower and we'll need to slow the descent and number of 
}


void dipup2() {
  for (int x = 0; x < 33; x++)
  {
    delay(2000);
    digup();
  }
}


//button interrupts
void UP_BUTTON_ISR() //button A)
{
  if (millis() > debounceTimer + 200)
  {
    buttonPushCounter++;
    debounceTimer = millis();
  }
}

void DOWN_BUTTON_ISR()//button B)
{
  if (millis() > debounceTimer + 200)
  {
    buttonPushCounter--;
    debounceTimer = millis();
  }
}

void SELECT_BUTTON_ISR() //button C)
{
  if (millis() > debounceTimer + 200)
  {
    select = true;
    debounceTimer = millis();
  }
}[code]

[/code]

Never mind, it was an equals = that had been used instead of a double == to define the else if (select) part of sprayMode!