Directions on my first FSM

//WBJB_FSM
#include <UTFT.h>
#include <URTouch.h>
#include <Servo.h> //use pin 9
UTFT    myGLCD(ILI9341_16, 38, 39, 40, 41);
URTouch  myTouch( 6, 5, 4, 3, 2);
enum states
{
  SHOW_IDLE,
  SHOW_FIRST_SECTION,
  SHOW_CREDITCARD_SECTION,
  SHOW_SECOND_SECTION,
  SHOW_REED_SECTION,
  SHOW_THIRD_SECTION,
  SHOW_DRAW_BUTTONS_SECTION
};
void setup()
{
  pinMode (creditcardPin, INPUT_PULLUP);
  digitalWrite (creditcardPin, HIGH);
  pinMode (goodreedPin, INPUT_PULLUP);
  digitalWrite (goodreedPin, HIGH);
  pinMode (badreedPin, INPUT_PULLUP);
  digitalWrite (badreedPin, HIGH);
}
void loop()
{
  timeRef = millis();
  // Uses the current state to decide what to process
  static int state = SHOW_FIRST_SECTION;
  switch (state)
  {
    case SHOW_IDLE:
      break;
    case SHOW_FIRST_SECTION:
      FirstSection();
      state = SHOW_CREDITCARD_SECTION;
      break;
    case SHOW_CREDITCARD_SECTION:
      creditcardFlag = digitalRead(21);
      if (creditcardFlag == 0) goodbuzzer(), state = SHOW_SECOND_SECTION;
      break;
    case SHOW_SECOND_SECTION:
      SecondSection();
      state = SHOW_REED_SECTION;
      break;
    case SHOW_REED_SECTION:
      goodreedFlag = digitalRead(20);
      badreedFlag = digitalRead(19);
      if (goodreedFlag == 0) goodbuzzer(), state = SHOW_THIRD_SECTION;
      else if (badreedFlag == 0) badbuzzer();
      break;
    case SHOW_THIRD_SECTION:
      ThirdSection();
      state = SHOW_DRAW_BUTTONS_SECTION;
      break;
    case SHOW_DRAW_BUTTONS_SECTION:
      drawbuttons();
      state = SHOW_IDLE;
      break;
  }
}
void FirstSection()
{
  //Display Page 1 and wait for progress timer
  {
    for (int L = 1; L <= 341;)
    {
      myGLCD.fillRect(0, 228, L, 230);
      delay (50); //wait 15 secconds
      L = L + 1;
    }
  }
  //Display Page 2 and wait for Pin 21 status change
}
void SecondSection()
{
  //Display first part of Page 3 and wait for status change on Pins 19 and 20
}
void ThirdSection()
{
  //Display the rest of Page 3 and wait for progress timer
  {
    for (int L = 1; L <= 341;)
    {
      myGLCD.fillRect(0, 228, L, 230);
      delay (50); //wait 15 secconds
      L = L + 1;
    }
  }
  // Display Page 4 and wait for progress timer
  {
    for (int L = 1; L <= 341;)
    {
      myGLCD.fillRect(0, 228, L, 230);
      delay (50); //wait 15 secconds
      L = L + 1;
    }
  }
}
void badbuzzer()
{
  // Generate a 1Khz tone for 0.5 second
}
void goodbuzzer()
{
  // Generate a 1Khz tone for 0.1 second
}
void drawbuttons()
{
  // Use sketch from URTouch_ButtonTest to draw touch button screen
}

Last week I asked for assistance on my first Arduino and C++ project. The project uses a 2650 and TFT screen and has multiple pages with hardware triggers and a touchscreen from the URTouch_ButtonTest example. It was suggested that I should use a state model. Most of my searches for FSM resulted with theoretical discussions, I was able to find two sketches that helped me to begin to understand the flow of the code. I have been able to create a FSM for the first four pages of my project, with the required hardware triggers, and a page to display the touchscreen buttons.

One of the references suggested that no additional code should be included with the states in the FSM void loop(). The original touchscreen sketch uses a void loop() to convert the touches to a string of digits. Can the code from the original sketch be directly added to the FSM void loop() ?

I assumed that the above was not possible and tried to create additional states and functions to process the touches. I created a new function in my FSM that has the code from the original void loop(), but have been able to test it yet. The original sketch uses functions void waitForIt(int x1, int y1, int x2, int y2) and void updateStr(int val) that were also called inside the original void loop(). The naming of these two functions is causing errors when I try to use them in my FSM. I have tried to rename the void waitForIt and get the following error messages for the two options I have tried.

with void waitForIt() , verify generates “ too many arguments to function ‘void waitForIt()’”

with void waitForIt(int x1, int y1, int x2, int y2), verify generates “expected primary-expression before ‘int’”

Any suggestions on how to proceed would be appreciated. I have included a copy of the appropriate lines from my FSM sketch.

One of the references suggested that no additional code should be included with the states in the FSM void loop().

That is up to you but you can, of course, include code in the code block for each state and/or call functions from there.

I note that in your code you have

    if (creditcardFlag == 0) goodbuzzer(), state = SHOW_SECOND_SECTION;

Which statement or statements are being executed if the condition returns true ? In my opinion this would be better as

     if (creditcardFlag == 0) 
     {
        goodbuzzer();
        state = SHOW_SECOND_SECTION;
      }

That way you can clearly see the code block to be executed if the test returns true.

The original touchscreen sketch uses a void loop() to convert the touches to a string of digits.

It is convenient to read inputs in the common code at the start of the loop() function and store the values returned in global variables. That way the values can be used throughout the program and have consistent values for each iteration of loop()

. I have included a copy of the appropriate lines from my FSM sketch.

It would be better if you posted the whole program

//WBJB_FSM
#include <UTFT.h>
#include <URTouch.h>
#include <Servo.h> //use pin 9
// Initialize display
UTFT    myGLCD(ILI9341_16, 38, 39, 40, 41);
URTouch  myTouch( 6, 5, 4, 3, 2);
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];
char Pass[5] = "";
char Last[5] = "";
char master[5] = "6187";
const int buzzerPin = 11;
const int badreedPin = 19;
const int goodreedPin = 20;
const int creditcardPin = 21;
int x, y, z;
int val;
int x1;
int x2;
int y1;
int y2;
int Pcount = 0;
int badreedFlag = 1;
int goodreedFlag = 1;
int creditcardFlag = 1;
int PassCounter = 0;
enum states
{
  SHOW_IDLE,
  SHOW_FIRST_SECTION,
  SHOW_CREDITCARD_SECTION,
  SHOW_SECOND_SECTION,
  SHOW_REED_SECTION,
  SHOW_THIRD_SECTION,
  SHOW_DRAW_BUTTONS_SECTION,
  SHOW_DISPLAY_INPUT_SECTION,
  SHOW_WAITFORIT_SECTION
};
states state;
unsigned long timeRef;
unsigned long button_time = 0;
unsigned long last_button_time = 0;
void setup()
{
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_HI);
  myGLCD.setFont(BigFont);
  myGLCD.setBackColor(0, 0, 255);
  pinMode (creditcardPin, INPUT_PULLUP);
  digitalWrite (creditcardPin, HIGH);
  pinMode (goodreedPin, INPUT_PULLUP);
  digitalWrite (goodreedPin, HIGH);
  pinMode (badreedPin, INPUT_PULLUP);
  digitalWrite (badreedPin, HIGH);
}
void loop()
{
  timeRef = millis();
  // Uses the current state to decide what to process
  static int state = SHOW_FIRST_SECTION;
  switch (state)
  {
    case SHOW_IDLE:
      break;
    case SHOW_FIRST_SECTION:
      FirstSection();
      state = SHOW_CREDITCARD_SECTION;
      break;
    case SHOW_CREDITCARD_SECTION:
      creditcardFlag = digitalRead(21);
      if (creditcardFlag == 0) goodbuzzer(), state = SHOW_SECOND_SECTION;
      break;
    case SHOW_SECOND_SECTION:
      SecondSection();
      state = SHOW_REED_SECTION;
      break;
    case SHOW_REED_SECTION:
      goodreedFlag = digitalRead(20);
      badreedFlag = digitalRead(19);
      if (goodreedFlag == 0) goodbuzzer(), state = SHOW_THIRD_SECTION;
      else if (badreedFlag == 0) badbuzzer();
      break;
    case SHOW_THIRD_SECTION:
      ThirdSection();
      state = SHOW_DRAW_BUTTONS_SECTION;
      break;
    case SHOW_DRAW_BUTTONS_SECTION:
      drawbuttons();
      state = SHOW_DISPLAY_INPUT_SECTION;
      break;
    case SHOW_DISPLAY_INPUT_SECTION:
      displayinput();
      waitForIt(int x1, int y1, int x2, int y2);
      updateStr();
      state = SHOW_IDLE;
      break;
  }
}
void FirstSection()
{
  //Page 1
  myGLCD.clrScr();
  myGLCD.setBackColor(0, 0, 0); // Sets the background color of the area where the text will be printed to black
  myGLCD.setColor(255, 255, 255); // Sets color to white
  myGLCD.drawBitmap(70, 10, 180, 90, camera); // Prints the security camera jpeg
  myGLCD.setFont(BigFont); // Sets font to big
  myGLCD.print("If you need to reset", LEFT, 130); // Prints the string on the screen
  myGLCD.print("/ reboot the program,", LEFT, 154); // Prints the string on the screen
  myGLCD.print("remove the battery.", LEFT, 178); // Prints the string on the screen
  myGLCD.print("Thank You.", CENTER, 202); // Prints the string on the screen
  myGLCD.setColor(0, 255, 0); // Sets color to green
  {
    for (int L = 1; L <= 341;)
    {
      myGLCD.fillRect(0, 228, L, 230);
      delay (50); //wait 15 secconds
      L = L + 1;
    }
  }
  myGLCD.clrScr();
  //Page 2
  myGLCD.setColor(255, 255, 0); // Sets color to yellow
  myGLCD.print("W B and J Bank", CENTER, 10); // Prints the string on the screen
  myGLCD.print("South Wales, NY", CENTER, 34); // Prints the string on the screen
  myGLCD.setColor(255, 0, 0); // Sets color to red
  myGLCD.fillRect(0, 54, 319, 56);
  myGLCD.setColor(255, 255, 255); // Sets color to white
  myGLCD.print("Welcome", CENTER, 60); // Prints the string on the screen
  myGLCD.print("To begin, please", LEFT, 84); // Prints the string on the screen
  myGLCD.print("insert and quickly", LEFT, 108); // Prints the string on the screen
  myGLCD.print("withdraw your card.", LEFT, 132); // Prints the string on the screen
  myGLCD.print("The next menu will", LEFT, 156); // Prints the string on the screen
  myGLCD.print("then display.", LEFT, 180); // Prints the string on the screen
  myGLCD.drawBitmap(64, 204, 191, 30, images3); // Prints the credit card jpeg
}
void SecondSection()
{
  //Page 3
  myGLCD.clrScr();
  myGLCD.setBackColor(0, 0, 0); // Sets the background color of the area where the text will be printed to black
  myGLCD.setColor(255, 255, 255); // Sets color to white
  myGLCD.setFont(BigFont); // Sets font to big
  myGLCD.print("You need an access", LEFT, 10); // Prints the string on the screen
  myGLCD.print("code to continue.", LEFT, 34); // Prints the string on the screen
  myGLCD.print("Use the supplied", LEFT, 58); // Prints the string on the screen
  myGLCD.print("tool to SLOWLY scan", LEFT, 82); // Prints the string on the screen
  myGLCD.print("the exterior of the", LEFT, 106); // Prints the string on the screen
  myGLCD.print("entire ammo can.", LEFT, 130); // Prints the string on the screen
}
void ThirdSection()
{
  myGLCD.setBackColor(0, 0, 0); // Sets the background color of the area where the text will be printed to black
  myGLCD.setColor(255, 255, 255); // Sets color to white
  myGLCD.setFont(BigFont); // Sets font to big
  myGLCD.print("The access code is", CENTER, 154); // Prints the string on the screen
  myGLCD.print("1678", CENTER, 178); // Prints the string on the screen
  myGLCD.print("Please record code", CENTER, 202); // Prints the string on the screen
  myGLCD.setColor(0, 255, 0); // Sets color to green
  {
    for (int L = 1; L <= 341;)
    {
      myGLCD.fillRect(0, 228, L, 230);
      delay (50); //wait 15 secconds
      L = L + 1;
    }
  }
  myGLCD.clrScr();
  myGLCD.setBackColor(0, 0, 0); // Sets the background color of the area where the text will be printed to black
  myGLCD.setColor(255, 255, 255); // Sets color to white
  myGLCD.setFont(BigFont); // Sets font to big
  myGLCD.print("The code is randomly", LEFT, 10); // Prints the string on the screen
  myGLCD.print("scrambled to protect", LEFT, 34); // Prints the string on the screen
  myGLCD.print("each customer.", LEFT, 58); // Prints the string on the screen
  myGLCD.print("You must figure out", LEFT, 82); // Prints the string on the screen
  myGLCD.print("the correct order", LEFT, 106); // Prints the string on the screen
  myGLCD.print("of the digits.", LEFT, 130); // Prints the string on the screen
  myGLCD.print("Use the eraser tip", LEFT, 154); // Prints the string on the screen
  myGLCD.print("as a stylus on the", LEFT, 178); // Prints the string on the screen
  myGLCD.print("keypad, BE GENTLE.", LEFT, 202); // Prints the string on the screen
  myGLCD.setColor(0, 255, 0); // Sets color to green
  {
    for (int L = 1; L <= 341;)
    {
      myGLCD.fillRect(0, 228, L, 230);
      delay (50); //wait 15 secconds
      L = L + 1;
    }
  }
}
void badbuzzer()
{
  for (int i = 0; i < 500; i++) //generate a 1Khz tone for 0.5 second
  {
    digitalWrite(buzzerPin, HIGH);
    delay(1);//delay 1ms
    digitalWrite(buzzerPin, LOW);
    delay(1);//delay 1ms
  }
}
void goodbuzzer()
{
  for (int i = 0; i < 100; i++) //generate a 1Khz tone for 0.1 second
  {
    digitalWrite(buzzerPin, HIGH);
    delay(1);//delay 1ms
    digitalWrite(buzzerPin, LOW);
    delay(1);//delay 1ms
  }
}

As requested here is the first half of my FSM sketch

void drawbuttons()
{
  // Draw the upper row of buttons
  myGLCD.clrScr();
  for (x = 0; x < 5; x++)
  {
    myGLCD.setColor(0, 0, 255);
    myGLCD.fillRoundRect (10 + (x * 60), 10, 60 + (x * 60), 60);
    myGLCD.setColor(255, 255, 255);
    myGLCD.drawRoundRect (10 + (x * 60), 10, 60 + (x * 60), 60);
    myGLCD.printNumI(x + 1, 27 + (x * 60), 27);
  }
  // Draw the center row of buttons
  for (x = 0; x < 5; x++)
  {
    myGLCD.setColor(0, 0, 255);
    myGLCD.fillRoundRect (10 + (x * 60), 70, 60 + (x * 60), 120);
    myGLCD.setColor(255, 255, 255);
    myGLCD.drawRoundRect (10 + (x * 60), 70, 60 + (x * 60), 120);
    if (x < 4)
      myGLCD.printNumI(x + 6, 27 + (x * 60), 87);
  }
  myGLCD.print("0", 267, 87);
  // Draw the lower row of buttons
  myGLCD.setColor(0, 0, 255);
  myGLCD.fillRoundRect (10, 130, 150, 180);
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (10, 130, 150, 180);
  myGLCD.print("Clear", 40, 147);
  myGLCD.setColor(0, 0, 255);
  myGLCD.fillRoundRect (160, 130, 300, 180);
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (160, 130, 300, 180);
  myGLCD.print("Enter", 190, 147);
  myGLCD.setBackColor (0, 0, 0);
}
void displayinput()
{
  while (true)
  {
    if (myTouch.dataAvailable())
      delay(50);
    {
      myTouch.read();
      x = myTouch.getX();
      y = myTouch.getY();
      if ((y >= 10) && (y <= 60)) // Upper row
      {
        if ((x >= 10) && (x <= 60)) // Button: 1
        {
          waitForIt(10, 10, 60, 60);
          updateStr('1');
        }
        if ((x >= 70) && (x <= 120)) // Button: 2
        {
          waitForIt(70, 10, 120, 60);
          updateStr('2');
        }
        if ((x >= 130) && (x <= 180)) // Button: 3
        {
          waitForIt(130, 10, 180, 60);
          updateStr('3');
        }
        if ((x >= 190) && (x <= 240)) // Button: 4
        {
          waitForIt(190, 10, 240, 60);
          updateStr('4');
        }
        if ((x >= 250) && (x <= 300)) // Button: 5
        {
          waitForIt(250, 10, 300, 60);
          updateStr('5');
        }
      }
      if ((y >= 70) && (y <= 120)) // Center row
      {
        if ((x >= 10) && (x <= 60)) // Button: 6
        {
          waitForIt(10, 70, 60, 120);
          updateStr('6');
        }
        if ((x >= 70) && (x <= 120)) // Button: 7
        {
          waitForIt(70, 70, 120, 120);
          updateStr('7');
        }
        if ((x >= 130) && (x <= 180)) // Button: 8
        {
          waitForIt(130, 70, 180, 120);
          updateStr('8');
        }
        if ((x >= 190) && (x <= 240)) // Button: 9
        {
          waitForIt(190, 70, 240, 120);
          updateStr('9');
        }
        if ((x >= 250) && (x <= 300)) // Button: 0
        {
          waitForIt(250, 70, 300, 120);
          updateStr('0');
        }
      }
      if ((y >= 130) && (y <= 180)) // Upper row
      {
        if ((x >= 10) && (x <= 150)) // Button: Clear
        {
          waitForIt(10, 130, 150, 180);
          Pass[0] = '�';
          Pcount = 0;
          myGLCD.setColor(0, 0, 0);
          myGLCD.fillRect(0, 192, 319, 239);
          myGLCD.fillRect(0, 208, 319, 239);
          myGLCD.fillRect(0, 224, 319, 239);
        }
        if ((x >= 160) && (x <= 300)) // Button: Enter
        {
          waitForIt(160, 130, 300, 180);
          if (Pcount > 0)
          {
            for (x = 0; x < Pcount + 1; x++)
            {
              Last[x] = Pass[x];
            }
            Pass[0] = '�';
            PassCounter = Pcount;
            Pcount = 0;
            myGLCD.setColor(0, 0, 0);
            myGLCD.fillRect(0, 208, 319, 239);
            myGLCD.setColor(0, 255, 0);
            myGLCD.print(Last, LEFT, 208);
          }
        }
      }
    }
  }
}
void waitForIt(int x1, int y1, int x2, int y2)
{
  myGLCD.setColor(255, 0, 0);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
  while (myTouch.dataAvailable())
    myTouch.read();
  myGLCD.setColor(255, 255, 255);
  myGLCD.drawRoundRect (x1, y1, x2, y2);
}
void updateStr()
{
  if (Pcount < 4)
  {
    Pass[Pcount] = val;
    Pass[Pcount + 1] = '�';
    Pcount++;
    myGLCD.setColor(0, 255, 0);
    myGLCD.print(Pass, LEFT, 224);
  }
  else
  {
    myGLCD.setColor(255, 0, 0);
    myGLCD.print("TOO MANY DIGITS!", CENTER, 192);
    delay(500);
    myGLCD.print("                ", CENTER, 192);
    delay(500);
    myGLCD.print("TOO MANY DIGITS!", CENTER, 192);
    delay(500);
    myGLCD.print("                ", CENTER, 192);
    delay(500);
    myGLCD.print("PRESS CLEAR TWICE!", CENTER, 192);
    delay(1000);
    myGLCD.print("                  ", CENTER, 192);
    myGLCD.setColor(0, 255, 0);
  }
}

Here is the second half of the FSM sketch, the complete sketch was too large to post.

waitForIt(int x1, int y1, int x2, int y2);

Here you are calling the function and declaring 4 new variables at the same time, or trying to.

You should pass existing variables so remove the type specifiers and use

waitForIt(x1, y1, x2, y2);