Case does not follow number call up

Hi, im relatively new to using an arduino so please go easy on me. A little background, im trying to fill a container with an amount of water, it doesn’t have to be exact but near enough. half way through filling id like to turn on 2 relay outputs that will be connected to a pump and heater and hold temperature.

Anyway ive been reading through some guides and I have come up with the below script. The problem I am having is that it will go through the on, ready and fill case, but then even though the command state changes to move on to the fillheat case it just appears to hang and I cant for the life of me understand why.

//----Libraries------
#include <LiquidCrystal_I2C.h>

//-----Defines-----
#define I2C_ADDR    0x3F
#define BACKLIGHT_PIN 3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7


//Define all the command states
#define ON 0
#define Ready 1
#define Fill 2
#define FillHeat 3
#define Complete 4
#define Relay 5


LiquidCrystal_I2C  lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);   //Name lcd pins

//-----CONSTANTS----- (wont change)
const int Startswitch = 3;
const int waterInRelay = 4;
const int heaterRelay = 5;
const int mixPumpRelay = 6;
const int R1 = waterInRelay;
const int R2 = heaterRelay;
const int R3 = mixPumpRelay;

//-----VARIABLES----- (will change)
int commandState = ON; //0=ON, 1=Ready, 2=Fill, 3=Fill/Heat, 4=Complete, 5=Relay


//-----Intrupt counter-----
volatile unsigned long isrCounter;
unsigned long pulseCount;
// Flow sensor FL-S402B = 600 pulses/l
// Flow sensor YF-S201 = 450 pulses/l
int calFactor = 600;
// convert pulses to litres
unsigned long waterVol = pulseCount/calFactor;
// Set volume to stop at = required volume in ltr x calFactor
unsigned long stopCount = 600;//**** SET FOR 1Ltr****

void setup() {

  Serial.begin(9600);

  pinMode(Startswitch, INPUT_PULLUP);   //configure pin 2 as an input and enable the internal pull-up resistor

  //configure outputs
  pinMode(R1, OUTPUT);
  digitalWrite (R1, HIGH);

  // Set LCD
  lcd.begin (16, 2);
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print ("Flow counter");     // signal initalization done
  lcd.setCursor(0, 1);
  lcd.print ("starting");
  delay (3000);
  lcd.clear();

  
  attachInterrupt(0, countP, RISING);

}  // End of setup


void loop() {
  bool Startbuttonstate = digitalRead(Startswitch);
  //Serial.println(Startbuttonstate);                      //print out the value of the pushbutton
  
  switch (commandState) {

    //----------------------
    case ON:
      Serial.println(commandState);
      clearLCD();
      for (int ONi = 3; ONi > 0; ONi--) {  //count down from 3
        selectLineOne();
        lcd.print("Elmo Industries");
        selectLineTwo();
        lcd.print("   Hello Dave");
        delay (1000);
      }

      commandState = Ready;
      delay(500);


      break;
    //---------------------
    
    case Ready:
      Serial.println(commandState);

      clearLCD();
      selectLineOne();
      //delay(100);
      lcd.print("Push button");     //Notify user that the system is ready
      selectLineTwo();
      lcd.print("to start");

      //if (Levelsensorstate) {   //(Levelsensorstate == HIGH) {   //check to make sure container is not already filled
      //LevelActivated();
      //delay(500);                      //blanked out as seems to be tripping even tho switch not made
      if (Startbuttonstate) {    //(Startbuttonstate == HIGH) {    //Wait for start button to be pressed
        commandState = Ready;
        delay(500);

      } else { //if start button is pressed start fill.

        clearLCD();
        selectLineOne();
        delay(100);
        lcd.print("   Starting");
        delay(2000);
        clearLCD();
        commandState = Fill; //Start flush countdown
      }

      break;
    //-------------------------
    
    case Fill:
      Serial.println(commandState);
      digitalWrite (R1, LOW);             //water in relay on, solenoid open
      delay(100);
      noInterrupts();
      long pulseCount = isrCounter;
      interrupts();
      lcd.setCursor(0,0);
      lcd.print("Total Vol");
      lcd.print (pulseCount);
      lcd.setCursor(0,1);
      lcd.print(waterVol);
      lcd.print(" Ltrs");
      if (pulseCount > (stopCount/2))
      {
        lcd.clear();
        selectLineOne();
        lcd.print("Starting Heat");
        selectLineTwo();
        lcd.print("and Mix");
        Serial.println("start heat mix");
        commandState = FillHeat; //set command state to fill and heat
        Serial.println("state switched fill heat");
        Serial.println(commandState);
      }

      break;
      //----------------------

      case FillHeat:
      Serial.println(commandState);
      digitalWrite (R1, LOW);             //water in relay on, solenoid open
      digitalWrite (R2, LOW);             //water heater on, solenoid open
      digitalWrite (R3, LOW);             //mixing pump on, solinoid open
      delay(100);
      noInterrupts();
      interrupts();
      lcd.setCursor(0,0);
      lcd.print("Total Vol");
      lcd.print (pulseCount);
      lcd.setCursor(0,1);
      lcd.print(waterVol);
      lcd.print(" Ltrs,Heat on");
      if (pulseCount > stopCount)
      {
        digitalWrite (R1, HIGH);
        lcd.clear();
        selectLineOne();
        lcd.print("Fill stopped");
        selectLineTwo();
        lcd.print(waterVol);
        lcd.print(" Litres");
        Serial.println("complete fill");
        commandState = Complete; //set command state to complete
        Serial.println("state switched");
        Serial.println(commandState);
      }

      break;
      //----------------------
      
    case Complete:
      clearLCD();
      selectLineOne();
      delay(500);
      lcd.print("  Water fill");
      selectLineTwo();
      lcd.print("  completed!");
      delay (2000);
      commandState = Ready;

      break;

   case Relay:
      Serial.println(commandState);
      digitalWrite (R1, LOW);
      delay (1000);
      digitalWrite (R1, HIGH);
      delay (1000);

      break;
  }

}  // end of loop

void countP()
{
  isrCounter++;
}

void clearLCD() {
  lcd.setCursor(0, 0);
  lcd.clear();
}

void selectLineOne() { //puts the cursor at line 0 char 0.
  lcd.setCursor(0,0); //position
}
void selectLineTwo() { //puts the cursor at line 0 char 0.
  lcd.setCursor(0,1); //position
}

So please any help would be greatly appreciated, or guidance if I could go about this using a different method.

the command state changes to move on to the fillheat case it just appears to hang and I cant for the life of me understand why.

One thing I notice is that you never update pulseCount in FillHeat like you do in Fill.

noInterrupts();
      interrupts();

compared to

noInterrupts();
      long pulseCount = isrCounter;
      interrupts();

Thanks for your reply. It was my understanding that I shouldn't need to put that as I had already called it up in the case before.

It was my understanding that I shouldn't need to put that as I had already called it up in the case before.

You misunderstand. You are no longer in that "case before", and the code block is not repeated magically in the current case. Each case is executed independently

cattledog: You misunderstand. You are no longer in that "case before", and the code block is not repeated magically in the current case. Each case is executed independently

So long as the previous case has a break; instruction.

switch (x) { case a: does some stuff break; case b: does other stuff

case c: does more stuff break; }

case a only executes some stuff case b executes other stuff AND more stuff case c only executes more stuff

In the FillHeat case you are testing pulseCount against stopCount, but pulseCount never gets incremented/changed. In the Fill case you establish a new local variable called pulseCount so from that point on within the switch statement, all references to pulseCount are for the local version.

DKWatson: In the FillHeat case you are testing pulseCount against stopCount, but pulseCount never gets incremented/changed. In the Fill case you establish a new local variable called pulseCount so from that point on within the switch statement, all references to pulseCount are for the local version.

so would I be better off making pulseCount a global variable so that it will be incremented/changed in any case that I wish to reference it in?

adwsystems: So long as the previous case has a break; instruction.

switch (x) { case a: does some stuff break; case b: does other stuff

case c: does more stuff break; }

case a only executes some stuff case b executes other stuff AND more stuff case c only executes more stuff

This was my understanding, hence how I have wrote the cases and why I am confused that when I ask it to go to case FillHeat after Fill, although the commandstate changes it doesn't run the case.

You have lots of Serial.print commands. How about posting your serial output showing what is and isn't working.

Here is the serial output

0
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
start heat mix
state switched fill heat
3

Although the command state changes to 3 this is where it stops. I added the serial.print commands to see if it would help me understand what was going on and try to debug. However this has kind of confused me more as it changes the case number to 3 yet wont run the third case

How about adding a default case with Serial.println("default error") ?

I don't use that LCD library anymore so I can't compile nor test your sketch.

I think I have done what you asked adwsystems. if I haven’t I apologise
here is the code

//----Libraries------
#include <LiquidCrystal_I2C.h>

//-----Defines-----
#define I2C_ADDR    0x3F
#define BACKLIGHT_PIN 3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7


//Define all the command states
#define ON 0
#define Ready 1
#define Fill 2
#define FillHeat 3
#define Complete 4
#define Relay 5


LiquidCrystal_I2C  lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);   //Name lcd pins

//-----CONSTANTS----- (wont change)
const int Startswitch = 3;
const int waterInRelay = 4;
const int heaterRelay = 5;
const int mixPumpRelay = 6;
const int R1 = waterInRelay;
const int R2 = heaterRelay;
const int R3 = mixPumpRelay;

//-----VARIABLES----- (will change)
int commandState = ON; //0=ON, 1=Ready, 2=Fill, 3=Fill/Heat, 4=Complete, 5=Relay


//-----Intrupt counter-----
volatile unsigned long isrCounter;
unsigned long pulseCount;
unsigned long pulseCount2;
// Flow sensor FL-S402B = 600 pulses/l
// Flow sensor YF-S201 = 450 pulses/l
int calFactor = 600;
// convert pulses to litres
unsigned long waterVol = (pulseCount+pulseCount2)/calFactor;
// Set volume to stop at = required volume in ltr x calFactor
unsigned long stopCount = 600;//**** SET FOR 1Ltr****

void setup() {

  Serial.begin(9600);

  pinMode(Startswitch, INPUT_PULLUP);   //configure pin 2 as an input and enable the internal pull-up resistor

  //configure outputs
  pinMode(R1, OUTPUT);
  digitalWrite (R1, HIGH);

  // Set LCD
  lcd.begin (16, 2);
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print ("Flow counter");     // signal initalization done
  lcd.setCursor(0, 1);
  lcd.print ("starting");
  delay (3000);
  lcd.clear();

  
  attachInterrupt(0, countP, RISING);

}  // End of setup


void loop() {
  bool Startbuttonstate = digitalRead(Startswitch);
  //Serial.println(Startbuttonstate);                      //print out the value of the pushbutton
  
  switch (commandState) {

    //----------------------
    case ON:
      Serial.println("Running ON case");
      Serial.println(commandState);
      
      clearLCD();
      for (int ONi = 3; ONi > 0; ONi--) {  //count down from 3
        selectLineOne();
        lcd.print("Elmo Industries");
        selectLineTwo();
        lcd.print("   Hello Dave");
        delay (1000);
      }

      commandState = Ready;
      Serial.println("commandState = ready");
      delay(500);


      break;
    //---------------------
    
    case Ready:
      Serial.println("Ready case running");
      Serial.println(commandState);

      clearLCD();
      selectLineOne();
      //delay(100);
      lcd.print("Push button");     //Notify user that the system is ready
      selectLineTwo();
      lcd.print("to start");

      //if (Levelsensorstate) {   //(Levelsensorstate == HIGH) {   //check to make sure container is not already filled
      //LevelActivated();
      //delay(500);                      //blanked out as seems to be tripping even tho switch not made
      if (Startbuttonstate) {    //(Startbuttonstate == HIGH) {    //Wait for start button to be pressed
        Serial.println("waiting for button press");
        commandState = Ready;
        delay(500);

      } else { //if start button is pressed start fill.

        Serial.println("button pressed");
        clearLCD();
        selectLineOne();
        delay(100);
        lcd.print("   Starting");
        delay(2000);
        clearLCD();
        commandState = Fill; //Start flush countdown
        Serial.println("commandState = Fill");
      }

      break;
    //-------------------------
    
    case Fill:
      Serial.println("Running Fill case");
      Serial.println(commandState);
      digitalWrite (R1, LOW);             //water in relay on, solenoid open
      delay(100);
      noInterrupts();
      long pulseCount = isrCounter;
      interrupts();
      lcd.setCursor(0,0);
      lcd.print("Total Vol");
      lcd.print (pulseCount);
      lcd.setCursor(0,1);
      lcd.print(waterVol);
      lcd.print(" Ltrs");
      if (pulseCount > (stopCount/2))
      {
        lcd.clear();
        selectLineOne();
        lcd.print("Starting Heat");
        selectLineTwo();
        lcd.print("and Mix");
        Serial.println("start heat mix");
        commandState = FillHeat; //set command state to fill and heat
        Serial.println(commandState);
        Serial.println("command state changed fill heat");
      }

      break;
      //----------------------

      case FillHeat:
      Serial.println(commandState);
      digitalWrite (R1, LOW);             //water in relay on, solenoid open
      digitalWrite (R2, LOW);             //water heater on, solenoid open
      digitalWrite (R3, LOW);             //mixing pump on, solinoid open
      delay(100);
      noInterrupts();
      long pulseCount2 = isrCounter;
      interrupts();
      lcd.setCursor(0,0);
      lcd.print("Total Vol");
      lcd.print (pulseCount2);
      lcd.setCursor(0,1);
      lcd.print(waterVol);
      lcd.print(" Ltrs,Heat on");
      if (pulseCount2 > stopCount)
      {
        digitalWrite (R1, HIGH);
        lcd.clear();
        selectLineOne();
        lcd.print("Fill stopped");
        selectLineTwo();
        lcd.print(waterVol);
        lcd.print(" Litres");
        Serial.println("complete fill");
        commandState = Complete; //set command state to complete
        Serial.println("state switched");
        Serial.println(commandState);
      }

      break;
      //----------------------
      
    case Complete:
      clearLCD();
      selectLineOne();
      delay(500);
      lcd.print("  Water fill");
      selectLineTwo();
      lcd.print("  completed!");
      delay (2000);
      commandState = Ready;

      break;

   case Relay:
      Serial.println(commandState);
      digitalWrite (R1, LOW);
      delay (1000);
      digitalWrite (R1, HIGH);
      delay (1000);

      break;
  }

}  // end of loop

void countP()
{
  isrCounter++;
}

void clearLCD() {
  lcd.setCursor(0, 0);
  lcd.clear();
}

void selectLineOne() { //puts the cursor at line 0 char 0.
  lcd.setCursor(0,0); //position
}
void selectLineTwo() { //puts the cursor at line 0 char 0.
  lcd.setCursor(0,1); //position
}

I am not sure, I can't find the word 'default'. Did you post the updated version?

In the switch statement add below the break; for case Relay:

default: Serial.println("Default Case Error");
 break;

It should look similar to:

   case Relay:
      Serial.println(commandState);
      digitalWrite (R1, LOW);
      delay (1000);
      digitalWrite (R1, HIGH);
      delay (1000);

      break;

    default: Serial.println("Default Case Error");
      break;
  }

Once you have the change, post the code and the serial output.

sorry wrong copy
Is this what you meant?

//----Libraries------
#include <LiquidCrystal_I2C.h>

//-----Defines-----
#define I2C_ADDR    0x3F
#define BACKLIGHT_PIN 3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7


//Define all the command states
#define ON 0
#define Ready 1
#define Fill 2
#define FillHeat 3
#define Complete 4
#define Relay 5
#define default 6


LiquidCrystal_I2C  lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);   //Name lcd pins

//-----CONSTANTS----- (wont change)
const int Startswitch = 3;
const int waterInRelay = 4;
const int heaterRelay = 5;
const int mixPumpRelay = 6;
const int R1 = waterInRelay;
const int R2 = heaterRelay;
const int R3 = mixPumpRelay;

//-----VARIABLES----- (will change)
int commandState = ON; //0=ON, 1=Ready, 2=Fill, 3=Fill/Heat, 4=Complete, 5=Relay, 6=default


//-----Intrupt counter-----
volatile unsigned long isrCounter;
unsigned long pulseCount;
unsigned long pulseCount2;
// Flow sensor FL-S402B = 600 pulses/l
// Flow sensor YF-S201 = 450 pulses/l
int calFactor = 600;
// convert pulses to litres
unsigned long waterVol = (pulseCount+pulseCount2)/calFactor;
// Set volume to stop at = required volume in ltr x calFactor
unsigned long stopCount = 600;//**** SET FOR 1Ltr****

void setup() {

  Serial.begin(9600);

  pinMode(Startswitch, INPUT_PULLUP);   //configure pin 2 as an input and enable the internal pull-up resistor

  //configure outputs
  pinMode(R1, OUTPUT);
  digitalWrite (R1, HIGH);

  // Set LCD
  lcd.begin (16, 2);
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print ("Flow counter");     // signal initalization done
  lcd.setCursor(0, 1);
  lcd.print ("starting");
  delay (3000);
  lcd.clear();

  
  attachInterrupt(0, countP, RISING);

}  // End of setup


void loop() {
  bool Startbuttonstate = digitalRead(Startswitch);
  //Serial.println(Startbuttonstate);                      //print out the value of the pushbutton
  
  switch (commandState) {

    //----------------------
    case ON:
      Serial.println("Running ON case");
      Serial.println(commandState);
      
      clearLCD();
      for (int ONi = 3; ONi > 0; ONi--) {  //count down from 3
        selectLineOne();
        lcd.print("Elmo Industries");
        selectLineTwo();
        lcd.print("   Hello Dave");
        delay (1000);
      }

      commandState = Ready;
      Serial.println("commandState = ready");
      delay(500);


      break;
    //---------------------
    
    case Ready:
      Serial.println("Ready case running");
      Serial.println(commandState);

      clearLCD();
      selectLineOne();
      //delay(100);
      lcd.print("Push button");     //Notify user that the system is ready
      selectLineTwo();
      lcd.print("to start");

      //if (Levelsensorstate) {   //(Levelsensorstate == HIGH) {   //check to make sure container is not already filled
      //LevelActivated();
      //delay(500);                      //blanked out as seems to be tripping even tho switch not made
      if (Startbuttonstate) {    //(Startbuttonstate == HIGH) {    //Wait for start button to be pressed
        Serial.println("waiting for button press");
        commandState = Ready;
        delay(500);

      } else { //if start button is pressed start fill.

        Serial.println("button pressed");
        clearLCD();
        selectLineOne();
        delay(100);
        lcd.print("   Starting");
        delay(2000);
        clearLCD();
        commandState = Fill; //Start flush countdown
        Serial.println("commandState = Fill");
      }

      break;
    //-------------------------
    
    case Fill:
      Serial.println("Running Fill case");
      Serial.println(commandState);
      digitalWrite (R1, LOW);             //water in relay on, solenoid open
      delay(100);
      noInterrupts();
      long pulseCount = isrCounter;
      interrupts();
      lcd.setCursor(0,0);
      lcd.print("Total Vol");
      lcd.print (pulseCount);
      lcd.setCursor(0,1);
      lcd.print(waterVol);
      lcd.print(" Ltrs");
      if (pulseCount > (stopCount/2))
      {
        lcd.clear();
        selectLineOne();
        lcd.print("Starting Heat");
        selectLineTwo();
        lcd.print("and Mix");
        Serial.println("start heat mix");
        commandState = FillHeat; //set command state to fill and heat
        Serial.println(commandState);
        Serial.println("command state changed fill heat");
      }

      break;
      //----------------------

      case FillHeat:
      Serial.println(commandState);
      digitalWrite (R1, LOW);             //water in relay on, solenoid open
      digitalWrite (R2, LOW);             //water heater on, solenoid open
      digitalWrite (R3, LOW);             //mixing pump on, solinoid open
      delay(100);
      noInterrupts();
      long pulseCount2 = isrCounter;
      interrupts();
      lcd.setCursor(0,0);
      lcd.print("Total Vol");
      lcd.print (pulseCount2);
      lcd.setCursor(0,1);
      lcd.print(waterVol);
      lcd.print(" Ltrs,Heat on");
      if (pulseCount2 > stopCount)
      {
        digitalWrite (R1, HIGH);
        lcd.clear();
        selectLineOne();
        lcd.print("Fill stopped");
        selectLineTwo();
        lcd.print(waterVol);
        lcd.print(" Litres");
        Serial.println("complete fill");
        commandState = Complete; //set command state to complete
        Serial.println("state switched");
        Serial.println(commandState);
      }

      break;
      //----------------------
      
    case Complete:
      clearLCD();
      selectLineOne();
      delay(500);
      lcd.print("  Water fill");
      selectLineTwo();
      lcd.print("  completed!");
      delay (2000);
      commandState = Ready;

      break;
      //------------------------------

   case Relay:
      Serial.println(commandState);
      digitalWrite (R1, LOW);
      delay (1000);
      digitalWrite (R1, HIGH);
      delay (1000);

      break;
      //-----------------------------
      
    case default: 
    
    Serial.println("Default Case Error");
    
    break;
  }

}  // end of loop

void countP()
{
  isrCounter++;
}

void clearLCD() {
  lcd.setCursor(0, 0);
  lcd.clear();
}

void selectLineOne() { //puts the cursor at line 0 char 0.
  lcd.setCursor(0,0); //position
}
void selectLineTwo() { //puts the cursor at line 0 char 0.
  lcd.setCursor(0,1); //position
}

serial monitor is

Running ON case
0
commandState = ready
Ready case running
1
waiting for button press
Ready case running
1
waiting for button press
Ready case running
1
waiting for button press
Ready case running
1
waiting for button press
Ready case running
1
waiting for button press
Ready case running
1
waiting for button press
Ready case running
1
button pressed
commandState = Fill
Running Fill case
2
Running Fill case
2
Running Fill case
2
Running Fill case
2
Running Fill case
2
Running Fill case
2
Running Fill case
2
Running Fill case
2
Running Fill case
2
start heat mix
3
command state changed fill heat

That's what I meant. The default case executes any time there is not a matching case above. If commandState got to be a value of 12, then default would execute.

You don't need #define default 6 Can you remove it and see if the serial output changes.

Based on the serial output the FillHeat case doesn't execute a single time. Furthermore it appears that no case is executing. I can't wait to find out what stupid little thing has been overlooked.

On an irrelevant note, why do you alternate between lcd.setCursor(0,0) and selectLineOne (or 0,1 and LineTwo)?

adwsystems: That's what I meant. The default case executes any time there is not a matching case above. If commandState got to be a value of 12, then default would execute.

You don't need #define default 6. Can you remove it and see if the serial output changes.

Based on the serial output the FillHeat case doesn't execute a single time. Furthermore it appears that no case is executing. I can't wait to find out what stupid little thing has been overlooked.

Thanks, I now understand what the default would do. I have removed the #define default 6, also realised that I had to remove case from case default. I ran the code again and the serial monitor comes back the same.

That was my feeling that for some reason the FillHeat case doesn't execute at all. I have tried changing the commandstate at the end of Fill to complete and relay and the same still happens.

adwsystems: On an irrelevant note, why do you alternate between lcd.setCursor(0,0) and selectLineOne (or 0,1 and LineTwo)?

I thought it may be an easier way to select the lines on the lcd screen that way, I just ran into this problem before changing the whole script. its sloppy sorry

Also thank you for your suggestions so far.

The next suggestion I would have is to either

(a) change #define to int

or

(b) change all of the state names to hard coded numbers

at least to see what happens.

I'm still hoping it is something tiny we have missed (I'm sure it is but can't see it yet).

elmo2002: so would I be better off making pulseCount a global variable so that it will be incremented/changed in any case that I wish to reference it in?

That would be my suggestion. It doesn't discount the fact though, that pulseCount is never updated anywhere outside from the Fill case. Testing to be > (stopCount/2) to switch state from Fill to FillHeat means that when entering FillHeat the value of pulseCount is (stopCount/2) + 1. Without further change it will never be > stopCount therefore it will never enter the code segment that will change state to Complete.

DKWatson: That would be my suggestion. It doesn't discount the fact though, that pulseCount is never updated anywhere outside from the Fill case. Testing to be > (stopCount/2) to switch state from Fill to FillHeat means that when entering FillHeat the value of pulseCount is (stopCount/2) + 1. Without further change it will never be > stopCount therefore it will never enter the code segment that will change state to Complete.

That's after the fact that it does not even execute the first line of the FillHeat case. Notice from the serial output posted, there should be a final '3' printed from the first step of FillHeat. FillHeat case doesn't execute, let alone end.