Void loop inside a switch case?

I am re-working an old project from about 9 years ago, to control/monitor the operation of a machine. I am using a 16x2 lcd with a UNO R3. A n.o. push button on the control box allows the operator to select a mode of operation, from a choice of 6, stepping through each one with a button press. These are labelled firstSequence, secondSequence etc. What I have so far is shown in the code;

#include <Wire.h>
#include "LiquidCrystal.h"

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

 
int WhichSequence =1;   // This variable stores the current Screen number
boolean hasChanged = true;
const int buttonPin = 8;    // the number of the pushbutton pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers
 
void setup()
{
  pinMode(buttonPin, INPUT);
 }
void loop()
{
 
  if (hasChanged == true) {
   
  switch(WhichSequence) {
    case 1:
    {
      firstSequence();
    }
      break;
   
    case 2:
      {
        secondSequence();
      }
      break;
   
    case 3:
      {
        thirdSequence();
      }
      break;
   
    case 4:
      {
        fourthSequence();
      }
      break;
   
    case 5:
      {
        fifthSequence();
      }
      break;
   
    case 6:
      {
        sixthSequence();
      }
      break;
    case 0:
      {
       
      }
      break;
    }
}
 
    //-------------------------------
    // BEGIN of the switch debouncing code
    int reading = digitalRead(buttonPin);
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }
 
if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:
 
    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;
 
      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH) {
        hasChanged = true;
        WhichSequence++;
       
       
      }
    } else {
      hasChanged = false;
    }
  }
  lastButtonState = reading;
  // END of the switch Debouncing code
  // --------------------------------------
  if (WhichSequence > 6){
    WhichSequence = 1;
  }
}
 
void firstSequence()
  {lcd.begin(16,2);
   lcd.clear();
   lcd.setCursor(0,0); // Column, line
   lcd.print("  Sequence 1");
   lcd.setCursor(0,1);
   lcd.print("  Count to 4");
  }
void secondSequence()
  {
    lcd.clear();
    lcd.setCursor(0,0); // Column, line
    lcd.print("Sequence 2");
    lcd.setCursor(0,1);
    lcd.print("Count to 5");
  }
void thirdSequence()
  {
    lcd.clear();
    lcd.setCursor(0,0); // Column, line
    lcd.print("  Sequence 3");
    lcd.setCursor(0,1);
    lcd.print("  Count to 6");
  }
void fourthSequence()
  {
    lcd.clear();
    lcd.setCursor(0,0); // Column, line
    lcd.print("Sequence 4");
    lcd.setCursor(0,1);
    lcd.print("Count to 7");
  }
void fifthSequence()
  {
    lcd.clear();
    lcd.setCursor(0,0); // Column, line
    lcd.print("  Sequence 5");
    lcd.setCursor(0,1);
    lcd.print("  Count to 8");
  }
void sixthSequence()
  {
    lcd.clear();
    lcd.setCursor(0,0); // Column, line
    lcd.print("Sequence 6");
    lcd.setCursor(0,1);
    lcd.print("Count to 9");
  }

During the operation, the machine moves to different positions, each position will actuate a n.o. sensor, some positions require another part of the machine to operate, this being carried out by turning on a solenoid valve controlled by the code.
Each sequence is different, for instance void thirdSequence() will be something like;
when machine is at -
position 1, lcd will show Sequence3 (line 1), position 1 (line2).
position 2, lcd will show Sequence3 (line 1), position 2 (line2).
position 3, lcd will show Sequence3 (line 1), position 3 (line2), plus a digital write output 1 (to operate solenoid 1)
position 4, lcd will show Sequence3 (line 1), position 4 (line2), plus a digital write output 2
(to operate solenoid 2)
position 5, lcd will show Sequence3 (line 1), position 5 (line2).
position 6, lcd will show Sequence3 (line 1), position 6 (line2).

Each activation of the sensor moves on the positions starting at 1 up to 6 and loops back to 1 again.

I now need to add further code to implement this operation.
I was thinking of adding switch cases within the void thirdSequence, each case incremented by the sensor,
or a void loop within the void thirdSequence something like;


if(count<6)
count +=1;
else
count=0;
}
lastState = ButtonState;
if (count==0)
{
digital write (whatever);
}
{
else if (count ==1)
{
digitalWrite(whatever);
}
{else if (count ==2)
{
digitalWrite(whatever);
}

// and so on...up to 6

Only thing is not sure if you can do either of these 2 methods. If not has anyone any ideas of how to code the 2nd part of the project.

Since void loop() is the main routine, I guess you can put it inside a switch case, but it'll never exit once inside void loop().

With the haschanged test outside of the whole structure, it won’t work. You could make it follow the Finite State Machine coding pattern more closely if you put the haschanged test inside the cases. Then, since case three could get lots of opportunity to run, it could have its own FSM to do more complicated tasks.

What I was thinking was in the original code if I selected case 3, the void loop inside it would run, but if I then changed to say case 6 a different void loop would run until I changed the switch case again, hope that makes sense.

There can only be one. Just like in the Lord of the rings.

Does it stay in the sequence forever, or does it do it just once?

If you don't need to scan the pushbutton, you can put the sequence inside thirdSequence() etc

Yes it stays in sequence 3 until the machine is shut down, so there could be hundreds of activations of the sensor.
The push button possibly may be used once to select the sequence required and then left, later in the day it might be necessary to change to a different sequence say sequence 6, then the machine goes again with lots of sensor activations and this time counting up to 9 then back to 1,2,3 so forth .

I suppose it is similar to a menu within a menu.
The main menu items are selected with a push button, the items within a menu is selected by the sensor, no enter button though.

I'm not sure how you select a sequence with one button then. As soon as you press it once, it will go into sequence 1. I think you need at least 2 buttons.

ETA: or perhaps short press to select a sequence, long press to enter the sequence

to say it very very clear:

there can be only ONE function loop().
But you can have an almost infinity amount of other "loops".
The only limit is the flash and RAM available on your microcontroller.

You seem to have not yet understood what the aim of

void loop() {
}

is.

the function loop() is the absolute most outer loop. You can imagine loop() as the borders of the whole universe. Except for the concept of a multi-verse (multiple universes) which would equal to multiple microcontrollers

And to keep the picture

void setup() {
}

equals to the big bang that "started" the universe to exist. Happened only one single time.

Everything else except function setup() has to be inside function loop()

But you can define additional functions.
You have this switch case directly inside function loop()

You can put this code into its own function
then your code looks like this

#include <Wire.h>
#include "LiquidCrystal.h"

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);


int WhichSequence = 1;  // This variable stores the current Screen number
boolean hasChanged = true;
const int buttonPin = 8;    // the number of the pushbutton pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup() {
  pinMode(buttonPin, INPUT);
}


void loop() {
  mySwitchCaseFunction();
  checkButton();
  // some more functions can be added here
}

mySwitchCaseFunction() {

  if (hasChanged == true) {

    switch (WhichSequence) {
      case 1:
        firstSequence();
        break;

      case 2:
        secondSequence();
        break;

      case 3:
        thirdSequence();
        break;

      case 4:
        fourthSequence();
        break;

      case 5:
        fifthSequence();
        break;

      case 6:
        sixthSequence();
        break;
      case 0:
        break;
    }
  }
}

void checkButton() {  
  //-------------------------------
  // BEGIN of the switch debouncing code
  int reading = digitalRead(buttonPin);
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;

      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH) {
        hasChanged = true;
        WhichSequence++;
      }
    } 
    else {
      hasChanged = false;
    }
  }
  lastButtonState = reading;
  // END of the switch Debouncing code
  // --------------------------------------
  if (WhichSequence > 6) {
    WhichSequence = 1;
  }
}

void firstSequence() { 
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0); // Column, line
  lcd.print("  Sequence 1");
  lcd.setCursor(0, 1);
  lcd.print("  Count to 4");
}

void secondSequence() {
  lcd.clear();
  lcd.setCursor(0, 0); // Column, line
  lcd.print("Sequence 2");
  lcd.setCursor(0, 1);
  lcd.print("Count to 5");
}

void thirdSequence() {
  lcd.clear();
  lcd.setCursor(0, 0); // Column, line
  lcd.print("  Sequence 3");
  lcd.setCursor(0, 1);
  lcd.print("  Count to 6");
}

void fourthSequence() {
  lcd.clear();
  lcd.setCursor(0, 0); // Column, line
  lcd.print("Sequence 4");
  lcd.setCursor(0, 1);
  lcd.print("Count to 7");
}

void fifthSequence() {
  lcd.clear();
  lcd.setCursor(0, 0); // Column, line
  lcd.print("  Sequence 5");
  lcd.setCursor(0, 1);
  lcd.print("  Count to 8");
}

void sixthSequence() {
  lcd.clear();
  lcd.setCursor(0, 0); // Column, line
  lcd.print("Sequence 6");
  lcd.setCursor(0, 1);
  lcd.print("Count to 9");
}

Running the code at the start of the thread, there is just one switch, each press steps on the sequence starting at firstSequence, the second, third, forth, fifth, sixth, back to first, the operator presses the button until it shows the sequence he requires. The machine is started up, when the mechanism gets to position1 a magnetc sensor is activated, the lcd shows "position 1", it the moves to "position 2", and when it gets to say position 3 (depending on which sequence has been selected) lcd shows "position 3" and solenoid is energised, etc, it finally gets to say position 6, the next sensor activation takes it back to showing "position 1" , then, "position 2".....

Ok, I think I understand. Something like this perhaps:

#include <Wire.h>
#include "LiquidCrystal.h"

//LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
LiquidCrystal lcd(8, 9, 4,5,6,7);

const int buttonPin = 2;      // the number of the pushbutton pin
const int sensorPin = 3;      // the number of the sensor pin
 
int WhichSequence = 1;   // This variable stores the current Screen number
boolean hasChanged = true;
int buttonState;              // the current reading from the input pin
int lastButtonState = LOW;    // the previous reading from the input pin
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers
 
void setup()
{
  pinMode(buttonPin, INPUT);
 }
void loop()
{
 
  if (hasChanged == true) {
   
  switch(WhichSequence) {
    case 1:
    {
      firstSequence();
    }
      break;
   
    case 2:
      {
        secondSequence();
      }
      break;
   
    case 3:
      {
        thirdSequence();
      }
      break;
   
    case 4:
      {
        fourthSequence();
      }
      break;
   
    case 5:
      {
        fifthSequence();
      }
      break;
   
    case 6:
      {
        sixthSequence();
      }
      break;
    case 0:
      {
       
      }
      break;
    }
}
 
    //-------------------------------
    // BEGIN of the switch debouncing code
    int reading = digitalRead(buttonPin);
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }
 
if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:
 
    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;
 
      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH) {
        hasChanged = true;
        WhichSequence++;
       
       
      }
    } else {
      hasChanged = false;
    }
  }
  lastButtonState = reading;
  // END of the switch Debouncing code
  // --------------------------------------
  if (WhichSequence > 6){
    WhichSequence = 1;
  }

  
  if (digitalRead(sensorPin) == HIGH)
  {
    performSequence (WhichSequence);
  }
}

void performSequence (int sequence)
{
  int count;
  switch (sequence)
  {
    case 1:
      count = 4;
      break;
      //todo: other cases
  }

  int position = 1;
  while (true)
  {
    lcd.setCursor(0,1);
    lcd.print("  Position ");
    lcd.print(position);

    while (digitalRead(sensorPin) == HIGH){}

    while (digitalRead(sensorPin) == LOW){}
    position ++;
    if (position > count)
      position = 1;
  }
}
 
void firstSequence()
  {lcd.begin(16,2);
   lcd.clear();
   lcd.setCursor(0,0); // Column, line
   lcd.print("  Sequence 1");
   lcd.setCursor(0,1);
   lcd.print("  Count to 4");
  }
void secondSequence()
  {
    lcd.clear();
    lcd.setCursor(0,0); // Column, line
    lcd.print("Sequence 2");
    lcd.setCursor(0,1);
    lcd.print("Count to 5");
  }
void thirdSequence()
  {
    lcd.clear();
    lcd.setCursor(0,0); // Column, line
    lcd.print("  Sequence 3");
    lcd.setCursor(0,1);
    lcd.print("  Count to 6");
  }
void fourthSequence()
  {
    lcd.clear();
    lcd.setCursor(0,0); // Column, line
    lcd.print("Sequence 4");
    lcd.setCursor(0,1);
    lcd.print("Count to 7");
  }
void fifthSequence()
  {
    lcd.clear();
    lcd.setCursor(0,0); // Column, line
    lcd.print("  Sequence 5");
    lcd.setCursor(0,1);
    lcd.print("  Count to 8");
  }
void sixthSequence()
  {
    lcd.clear();
    lcd.setCursor(0,0); // Column, line
    lcd.print("Sequence 6");
    lcd.setCursor(0,1);
    lcd.print("Count to 9");
  }

loop() is a fonction like any other, it's not the "main routine" as you call it. when the loop() function is done, it returns to its caller.

The IDE generates a main() function which looks like this (simplified)

int main(void) {
	init();
	setup();
	for (;;) loop();
	return 0;
}

init() configures the hardware the arduino way, setup() is your chance to configure your project the way you want and then there is an infinite repeat statement (the for loop) calling the loop() function. That's why the loop() function loops.

if you were going to call loop() from the loop() function, that's fine. It's called recursion. You can do that as long as there is a path to exit the recursion (or the optimiser flattens this out for you) otherwise you'll run out of stack memory.

Thanks for that code Bob, I have upload it to my UNO, changed the lcd pin connections.
I can step through the sequences with the button, if I stop on a sequence and then operate the sensor input it steps through the positions but once I have done this I can no longer use the switch to change to another sequence. Also position changes when switch contact closes and again when it opens, not just when it closes but that doesn't really matter at this stage. I have both inputs pulled to 5V+ with 10k resistors.

Thanks for clarifying. The way I've perceived it, setup = init and loop = main. So it's more of virtual aspect of it, would you agree?

Not sure what you mean by "virtual". In C / C++ at developer level, there is not "init" Just main() that does it all.

(The compiler does generate code that runs before main()).

you can try this code

void setup() {
  Serial.begin(115200);
}

void loop() {
  static byte depth = 0;
  if (depth >= 10) return; // <===== end of recursion
  Serial.println(depth++);
  loop();                  // <===== recursion
}

you should see the terminal counting from 0 to 9 and then nothing gets printed anymore. The loop will happily keep looping but will do nothing.

1 Like

Sorry, I think my switches are active high. I put the debounce in a function, and rearranged things slightly. Now the sequence loops exits when the button is pressed.

It would probably be a good idea to debounce the sensor input as well.

#include <Wire.h>
#include "LiquidCrystal.h"

//LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const int buttonPin = 2;  // the number of the pushbutton pin
const int sensorPin = 3;  // the number of the sensor pin

int WhichSequence = 1;  // This variable stores the current Screen number
boolean hasChanged = true;
int buttonState;                     // the current reading from the input pin
int lastButtonState = LOW;           // the previous reading from the input pin
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup()
{
  pinMode(buttonPin, INPUT);
  pinMode(sensorPin, INPUT_PULLUP);
}

bool checkButton(void)
{
  //-------------------------------
  // BEGIN of the switch debouncing code
  int reading = digitalRead(buttonPin);
  if (reading != lastButtonState)
  {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay)
  {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState)
    {
      buttonState = reading;

      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH)
      {
        hasChanged = true;
        WhichSequence++;
        if (WhichSequence > 6)
        {
          WhichSequence = 1;
        }
      }
    }
    else
    {
      // hasChanged = false;
    }
  }
  lastButtonState = reading;
  // END of the switch Debouncing code
  // --------------------------------------

  return hasChanged;
}

void loop()
{

  if (hasChanged == true)
  {
    hasChanged = false;
    switch (WhichSequence)
    {
      case 1:
        {
          firstSequence();
        }
        break;

      case 2:
        {
          secondSequence();
        }
        break;

      case 3:
        {
          thirdSequence();
        }
        break;

      case 4:
        {
          fourthSequence();
        }
        break;

      case 5:
        {
          fifthSequence();
        }
        break;

      case 6:
        {
          sixthSequence();
        }
        break;
      case 0:
        {
        }
        break;
    }
  }

  checkButton();

  if (digitalRead(sensorPin) == LOW)
  {
    performSequence(WhichSequence);
  }
}

void performSequence(int sequence)
{
  int count;
  switch (sequence)
  {
    case 1:
      count = 4;
      break;
      //todo: other cases
  }

  int position = 1;

  while (!hasChanged)
  {
    lcd.setCursor(0, 1);
    lcd.print("  Position ");
    lcd.print(position);

    while ((digitalRead(sensorPin) == LOW) && !checkButton())
    {
    }

    while ((digitalRead(sensorPin) == HIGH) && !checkButton())
    {
    }

    position++;
    if (position > count)
      position = 1;
  }
}

void firstSequence()
{
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);  // Column, line
  lcd.print("  Sequence 1");
  lcd.setCursor(0, 1);
  lcd.print("  Count to 4");
}
void secondSequence()
{
  lcd.clear();
  lcd.setCursor(0, 0);  // Column, line
  lcd.print("Sequence 2");
  lcd.setCursor(0, 1);
  lcd.print("Count to 5");
}
void thirdSequence()
{
  lcd.clear();
  lcd.setCursor(0, 0);  // Column, line
  lcd.print("  Sequence 3");
  lcd.setCursor(0, 1);
  lcd.print("  Count to 6");
}
void fourthSequence()
{
  lcd.clear();
  lcd.setCursor(0, 0);  // Column, line
  lcd.print("Sequence 4");
  lcd.setCursor(0, 1);
  lcd.print("Count to 7");
}
void fifthSequence()
{
  lcd.clear();
  lcd.setCursor(0, 0);  // Column, line
  lcd.print("  Sequence 5");
  lcd.setCursor(0, 1);
  lcd.print("  Count to 8");
}
void sixthSequence()
{
  lcd.clear();
  lcd.setCursor(0, 0);  // Column, line
  lcd.print("Sequence 6");
  lcd.setCursor(0, 1);
  lcd.print("Count to 9");
}

Virtual aspect = how a user see it. I learned more, never knew main is always present and invisible.

Interesting sketch btw.

OK - "conceptual" (mental or abstract representation of something) maybe was the word you were looking for then?

Thanks very much, we are almost there.
I have now added some more cases so the sensor count for each sequence is correct.
Only one thing left is to code a digitalWrite to energise a solenoid for some of the positions...(different positions for each sequence)
My final code so far is;

#include <Wire.h>
#include "LiquidCrystal.h"

//LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

const int buttonPin = 2;  // the number of the pushbutton pin
const int sensorPin = 3;  // the number of the sensor pin

int WhichSequence = 1;  // This variable stores the current Screen number
boolean hasChanged = true;
int buttonState;                     // the current reading from the input pin
int lastButtonState = LOW;           // the previous reading from the input pin
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers

void setup()
{
  pinMode(buttonPin, INPUT);
  pinMode(sensorPin, INPUT_PULLUP);
}

bool checkButton(void)
{
  //-------------------------------
  // BEGIN of the switch debouncing code
  int reading = digitalRead(buttonPin);
  if (reading != lastButtonState)
  {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay)
  {
    // whatever the reading is at, it's been there for longer
    // than the debounce delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState)
    {
      buttonState = reading;

      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH)
      {
        hasChanged = true;
        WhichSequence++;
        if (WhichSequence > 6)
        {
          WhichSequence = 1;
        }
      }
    }
    else
    {
      // hasChanged = false;
    }
  }
  lastButtonState = reading;
  // END of the switch Debouncing code
  // --------------------------------------

  return hasChanged;
}

void loop()
{

  if (hasChanged == true)
  {
    hasChanged = false;
    switch (WhichSequence)
    {
      case 1:
        {
          firstSequence();
        }
        break;

      case 2:
        {
          secondSequence();
        }
        break;

      case 3:
        {
          thirdSequence();
        }
        break;

      case 4:
        {
          fourthSequence();
        }
        break;

      case 5:
        {
          fifthSequence();
        }
        break;

      case 6:
        {
          sixthSequence();
        }
        break;
      case 0:
        {
        }
        break;
    }
  }

  checkButton();

  if (digitalRead(sensorPin) == LOW)
  {
    performSequence(WhichSequence);
  }
}

void performSequence(int sequence)
{
  int count;
  switch (sequence)
  {
    case 1:
      count = 4;
      break;
      //todo: other cases

    case 2:
      count = 5;
      break;

    case 3:
      count = 6;
      break;    

    case 4:
      count = 7;
      break;  

    case 5:
      count = 8;
      break;  

    case 6:
      count = 9;
      break;    
  }

  int position = 1;

  while (!hasChanged)
  {
    lcd.setCursor(0, 1);
    lcd.print("  Position ");
    lcd.print(position);

    while ((digitalRead(sensorPin) == LOW) && !checkButton())
    {
    }

    while ((digitalRead(sensorPin) == HIGH) && !checkButton())
    {
    }

    position++;
    if (position > count)
      position = 1;
  }
}

void firstSequence()
{
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);  // Column, line
  lcd.print("  Sequence 1");
  lcd.setCursor(0, 1);
  lcd.print("  Count to 4");
}
void secondSequence()
{
  lcd.clear();
  lcd.setCursor(0, 0);  // Column, line
  lcd.print("Sequence 2");
  lcd.setCursor(0, 1);
  lcd.print("Count to 5");
}
void thirdSequence()
{
  lcd.clear();
  lcd.setCursor(0, 0);  // Column, line
  lcd.print("  Sequence 3");
  lcd.setCursor(0, 1);
  lcd.print("  Count to 6");
}
void fourthSequence()
{
  lcd.clear();
  lcd.setCursor(0, 0);  // Column, line
  lcd.print("Sequence 4");
  lcd.setCursor(0, 1);
  lcd.print("Count to 7");
}
void fifthSequence()
{
  lcd.clear();
  lcd.setCursor(0, 0);  // Column, line
  lcd.print("  Sequence 5");
  lcd.setCursor(0, 1);
  lcd.print("  Count to 8");
}
void sixthSequence()
{
  lcd.clear();
  lcd.setCursor(0, 0);  // Column, line
  lcd.print("Sequence 6");
  lcd.setCursor(0, 1);
  lcd.print("Count to 9");
}