'check' was not declared in this scope issue

Hi guys if you’ve seen some of my other posts you’ll know I’m a newbie to microcontrollers and c++. One issue I am having with my coding is as mentioned in the subject error’s saying check was not declared in this scope. From my understanding you don’t have to declare a check as something else so I am unsure as to what the issue is. I will attach an image of the issue underneath. Thanks for the help and patience guys/girls! :slight_smile:

char dataIn = 'S';       //CharacterData coming from the phone.
int pinLeftTrackFB = 13;    //Pin controls left track bank forward and backward.
int pinRightTrackFB = 14;   //Pin controls right track bank forward and backward.
int BrakeLeftTrackFB = 8;   //Pin that enables/disables the left track bank.
int BrakeRightTrackFB = 15;  //Pin that enables/disables the right track bank
int pinLeftRightSpeed = 3;   //Pin that sets the speed for the Left-Right motor.
int pinLeftTrackSpeed = 11;   //Pin that sets the speed for the Left track bank.
int pinRightTrackSpeed = 16;  //Pin that sets the speed for the Right track bank.
int pinBrakeLeftTrackFB = 1;  //Pin that brakes left track.
int pinBrakeRightTrackFB = 2;  //Pin that brakes right track.
int pincamerapower = 4;    //Pin that activates power to front camera.
int pinlights = 7;   //Pin turns on led’s around tank.
char determinant;    //Used in the check function, stores the character received from the phone.
char det;    //Used in the loop function, stores the character received from the phone.
int velocity = 0;    //Stores the speed based on the character sent by phone.

void setup()
{
//  NOTE: Once Bluetooth module is received find the Bluetooth unit number and put it in brackets of serial begin.
Serial.begin(24634);   //Initialize serial communication with Bluetooth module at underlined number btu.
pinMode(pinLeftTrackFB, OUTPUT);
pinMode(pinRightTrackFB, OUTPUT);
pinMode(pinBrakeLeftTrackFB, OUTPUT);
pinMode(pinBrakeRightTrackFB, OUTPUT);
pinMode(pinLeftRightSpeed, OUTPUT);
pinMode(pinLeftTrackSpeed, OUTPUT);
pinMode(pinRightTrackSpeed, OUTPUT);
pinMode(pincamerapower, OUTPUT);
pinMode(pinlights, OUTPUT);
}

void loop()
{
   det = check();
     while (det == 'F')  //If incoming data is an F, denotes the function move forward
     {
digitalWrite(pinLeftTrackFB, LOW);
digitalWrite(pinRightTrackFB, LOW);
digitalWrite(pinBrakeLeftTrackFB, LOW);
digitalWrite(pinBrakeRightTrackFB, LOW);
analogWrite(pinLeftTrackFB, velocity);
analogWrite(pinRightTrackFB, velocity);
analogWrite(pinLeftTrackSpeed,255);
analogWrite(pinRightTrackSpeed,255);
det = check();
}
      while (det == 'B')   //if incoming data is a B, move back
      {    
digitalWrite(pinLeftTrackFB, HIGH);
digitalWrite(pinRightTrackFB, HIGH);
digitalWrite(pinBrakeLeftTrackFB, LOW);
digitalWrite(pinBrakeRightTrackFB, LOW);
analogWrite(pinLeftTrackFB, velocity);
analogWrite(pinRightTrackFB, velocity);
analogWrite(pinLeftTrackSpeed,-255);
analogWrite(pinRightTrackSpeed,-255);
          det = check();          
      } 

      while (det == 'L')   //if incoming data is a L, move wheels left
      {     
digitalWrite(pinLeftTrackFB, LOW);
digitalWrite(pinRightTrackFB, HIGH);
digitalWrite(pinBrakeLeftTrackFB, LOW);
digitalWrite(pinBrakeRightTrackFB, LOW);
analogWrite(pinLeftTrackFB, velocity);
analogWrite(pinRightTrackFB, velocity);
analogWrite(pinLeftTrackSpeed,0);
analogWrite(pinRightTrackSpeed,255);
det = check();          
      }  
      while (det == 'R')   //if incoming data is a R, move tank right
      {    
digitalWrite(pinBrakeLeftTrackFB,HIGH);
digitalWrite(pinBrakeRightTrackFB,LOW);
analogWrite(pinLeftTrackFB, velocity);
analogWrite(pinRightTrackFB, velocity);
analogWrite(pinLeftTrackSpeed,255);
analogWrite(pinRightTrackSpeed,0);
det=check();
}
while (det == 'S')  //if incoming data is a S, stop
{
digitalWrite(pinLeftTrackFB, LOW);
digitalWrite(pinRightTrackFB, LOW);
analogWrite(pinLeftTrackSpeed,0);
analogWrite(pinRightTrackSpeed,0);
det = check();
}

int check()

  if (Serial.available() > 0)    //Check for data on the serial lines.
  {   
    dataIn = Serial.read();  //Get the character sent by the phone and store it in 'dataIn'.
        if (dataIn == 'F')
        {     
          determinant = 'F';
        }  
        else if (dataIn == 'B')
        { 
          determinant = 'B'; 
        }
        else if (dataIn == 'L')  
        { 
          determinant = 'L';
        }
        else if (dataIn == 'R')  
        { 
          determinant = 'R';
        } 
        else if (dataIn == 'I')  
        { 
          determinant = 'I'; 
        }  
        else if (dataIn == 'J')  
        {  
          determinant = 'J';
        }          
        else if (dataIn == 'G') 
        {
          determinant = 'G'; 
        }    
        else if (dataIn == 'H')  
        {
          determinant = 'H'; 
        }   
        else if (dataIn == 'S') 
        {
          determinant = 'S';
        }
        else if (dataIn == '0') 
        {
          velocity = 0;    //"velocity" does not need to be returned.
        }
        else if (dataIn == '1') 
        {
          velocity = 25;
        }
        else if (dataIn == '2') 
        {
          velocity = 50;
        }
        else if (dataIn == '3') 
        {
          velocity = 75;
        }
        else if (dataIn == '4') 
        {
          velocity = 100;
        }
        else if (dataIn == '5') 
        {
          velocity = 125;
        }
        else if (dataIn == '6') 
        {
          velocity = 150;
        }
        else if (dataIn == '7') 
        {
          velocity = 175;
        }
        else if (dataIn == '8') 
        {
          velocity = 200;
        }
        else if (dataIn == '9') 
        {
          velocity = 225;
        }
        else if (dataIn == 'q') 
        {
          velocity = 255;
        }
        else if (dataIn == 'U') 
        {
          determinant = 'U';
        }
        else if (dataIn == 'u') 
        {
          determinant = 'u';
        }
        else if (dataIn == 'W') 
        {
          determinant = 'W';
        }
       
        else if (dataIn == 'w') 
        {
          determinant = 'w';
        }
  }
return determinant;
}

Your function “check” is missing its {}…

int check()
{   //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>. needs this, and closing one later
  if (Serial.available() > 0)    //Check for data on the serial lines.
  {   
    dataIn = Seri

http://arduino.cc/en/Reference/FunctionDeclaration

  int check()What is this line doing [u]inside[/u] the loop() function ?

Hi I've put it inside the loop because from what I know it's meant to recheck once the code has been run through and loops. I'm at odds with it as I had it working perfectly before and I did something to it, no idea what and now it won't work grrr

But "int check()" is a function, so it must be outside of loop, structured ala that link I posted.

The line "det = check()" calls the function named check, which has to be outside of loop.

Outline:

void setup()
{
//you can call check from here
}

void loop()
{
//and you can call check from here
}


// and then you code check down here, below loop()
// edit.... or you can put it riiiiiight at the top, above setup() but it's more usual to go here

int check()
{
// blah
}

You cannot put a function definition inside another function, at least not in this particular dialect of C/C++. I'm surprised it compiles.

 int check()Looks like the start of a function definition. If that is what it is meant to be then it does not belong inside loop()

Try Auto Formatting the code to fix the indentation and you may see what I am saying more clearly. As it stands at the moment you do not actually have a check() function.

Also if you don't mind my asking where would I place the close bracket in the code to get rid of this issue? THanks in advance

It might be there already, could be this one:

        else if (dataIn == 'w') 
        {
          determinant = 'w';
        }
  }
return determinant;
} //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

In the IDE, when you park cursor just after a bracket of any shape, it puts a box around its partner so you can check the pairings. See attached pic, not your code though. Red line is cursor.

brackets.PNG

So the issues I am having is this, I keep coming up with a compiling error and although I have gone through my work with a fine tooth comb I can’t find the issue I am using similar code to create my code and after comparing the two I cant see where and why I am coming up with this issue as the code is almost identical in nature.
Any help will be greatly
I will put the code in two seperate comments as I am exceeding character limit

This is the good code

char dataIn = 'S';        //Character/Data coming from the phone.
int pinForwardBack = 13;     //Pin that controls the car's Forward-Back motor.
int pinLeftRight = 12;       //Pin that controls the car's Left-Right motor.
int pinBrakeLeftRight = 9;  //Pin that enables/disables Left-Right motor.
int pinBrakeForwardBack = 8;  //Pin that enables/disables Forward-Back motor.
int pinLeftRightSpeed = 3;    //Pin that sets the speed for the Left-Right motor.
int pinForwardBackSpeed = 11;  //Pin that sets the speed for the Forward-Back motor.
int pinfrontLights = 4;    //Pin that activates the Front lights.
int pinbackLights = 7;    //Pin that activates the Back lights.
char determinant;         //Used in the check function, stores the character received from the phone.
char det;                 //Used in the loop function, stores the character received from the phone.
int velocity = 0;    //Stores the speed based on the character sent by the phone.

void setup() 
{       
//*************NOTE: If using Bluetooth Mate Silver use 115200 btu
//                   If using MDFLY Bluetooth Module use 9600 btu
Serial.begin(115200);  //Initialize serial communication with Bluetooth module at 115200 btu.
pinMode(pinForwardBack, OUTPUT);
pinMode(pinLeftRight, OUTPUT);
pinMode(pinBrakeLeftRight, OUTPUT);
pinMode(pinBrakeForwardBack, OUTPUT);
pinMode(pinLeftRightSpeed , OUTPUT);
pinMode(pinForwardBackSpeed , OUTPUT);
pinMode(pinfrontLights , OUTPUT);
pinMode(pinbackLights , OUTPUT);
}

void loop()
{ 
    det = check();
      while (det == 'F')   //if incoming data is a F, move forward
      {     
          digitalWrite(pinForwardBack, LOW); 
          digitalWrite(pinBrakeForwardBack, LOW);
          analogWrite(pinForwardBackSpeed,velocity);
          analogWrite(pinLeftRightSpeed,0);  //To make the Left/Right Motor not move, you just need to make its speed 0.    
          det = check();          
      }  
      while (det == 'B')   //if incoming data is a B, move back
      {    
          digitalWrite(pinForwardBack, HIGH); 
          digitalWrite(pinBrakeForwardBack, LOW);
          analogWrite(pinForwardBackSpeed,velocity); 
          analogWrite(pinLeftRightSpeed,0);         
          det = check();          
      } 

      while (det == 'L')   //if incoming data is a L, move wheels left
      {     
          digitalWrite(pinLeftRight, HIGH);
          digitalWrite(pinBrakeLeftRight, LOW);
          digitalWrite(pinForwardBack, LOW);
          analogWrite(pinForwardBackSpeed,0);    //To make the Forward/Back Motor not move, you just need to make its speed 0.
          analogWrite(pinLeftRightSpeed,255);        
          det = check();          
      }  
      while (det == 'R')   //if incoming data is a R, move wheels right
      {    
          digitalWrite(pinLeftRight, LOW);
          digitalWrite(pinBrakeLeftRight, LOW);
          digitalWrite(pinForwardBack, LOW);
          analogWrite(pinForwardBackSpeed,0);
          analogWrite(pinLeftRightSpeed,255);         
          det = check();          
      }
     
      while (det == 'I')   //if incoming data is a I, turn right forward
      {     
          digitalWrite(pinLeftRight, LOW);
          digitalWrite(pinForwardBack, LOW);          
          digitalWrite(pinBrakeLeftRight, LOW); 
          digitalWrite(pinBrakeForwardBack, LOW);  
          analogWrite(pinForwardBackSpeed,velocity);
          analogWrite(pinLeftRightSpeed,255);                  
          det = check();          
      }  
      while (det == 'J')   //if incoming data is a J, turn right back
      {      
          digitalWrite(pinLeftRight, LOW);
          digitalWrite(pinForwardBack, HIGH);         
          digitalWrite(pinBrakeLeftRight, LOW); 
          digitalWrite(pinBrakeForwardBack, LOW);
          analogWrite(pinForwardBackSpeed,velocity);
          analogWrite(pinLeftRightSpeed,255);          
          det = check();          
      }          
      while (det == 'G')   //if incoming data is a G, turn left forward
      { 
          digitalWrite(pinLeftRight, HIGH);       
          digitalWrite(pinForwardBack, LOW);
          digitalWrite(pinBrakeLeftRight, LOW); 
          digitalWrite(pinBrakeForwardBack, LOW); 
          analogWrite(pinForwardBackSpeed,velocity);
          analogWrite(pinLeftRightSpeed,255);          
          det = check();          
      }    
      while (det == 'H')   //if incoming data is a H, turn left back
      {
          digitalWrite(pinLeftRight, HIGH);
          digitalWrite(pinForwardBack, HIGH); 
          digitalWrite(pinBrakeLeftRight, LOW); 
          digitalWrite(pinBrakeForwardBack, LOW);
          analogWrite(pinForwardBackSpeed,velocity);
          analogWrite(pinLeftRightSpeed,255);          
          det = check();                                              
      }   
      while (det == 'S')   //if incoming data is a S, stop
      {
          digitalWrite(pinForwardBack, LOW); 
          digitalWrite(pinLeftRight, LOW);
          analogWrite(pinForwardBackSpeed,0);
          analogWrite(pinLeftRightSpeed,0);          
          det = check(); 
      }
      while (det == 'U')   //if incoming data is a U, turn ON front lights
      {
          digitalWrite(pinfrontLights, HIGH);          
          det = check(); 
      }
      while (det == 'u')   //if incoming data is a u, turn OFF front lights
      {
          digitalWrite(pinfrontLights, LOW);          
          det = check(); 
      }
      while (det == 'W')   //if incoming data is a W, turn ON back lights
      {
          digitalWrite(pinbackLights, HIGH);          
          det = check(); 
      }
      while (det == 'w')   //if incoming data is a w, turn OFF back lights
      {
          digitalWrite(pinbackLights, LOW);
          det = check(); 
      }
}

int check()
{
  if (Serial.available() > 0)    //Check for data on the serial lines.
  {   
    dataIn = Serial.read();  //Get the character sent by the phone and store it in 'dataIn'.
        if (dataIn == 'F')
        {     
          determinant = 'F';
        }  
        else if (dataIn == 'B')
        { 
          determinant = 'B'; 
        }
        else if (dataIn == 'L')  
        { 
          determinant = 'L';
        }
        else if (dataIn == 'R')  
        { 
          determinant = 'R';
        } 
        else if (dataIn == 'I')  
        { 
          determinant = 'I'; 
        }  
        else if (dataIn == 'J')  
        {  
          determinant = 'J';
        }          
        else if (dataIn == 'G') 
        {
          determinant = 'G'; 
        }    
        else if (dataIn == 'H')  
        {
          determinant = 'H'; 
        }   
        else if (dataIn == 'S') 
        {
          determinant = 'S';
        }
        else if (dataIn == '0') 
        {
          velocity = 0;    //"velocity" does not need to be returned.
        }
        else if (dataIn == '1') 
        {
          velocity = 25;
        }
        else if (dataIn == '2') 
        {
          velocity = 50;
        }
        else if (dataIn == '3') 
        {
          velocity = 75;
        }
        else if (dataIn == '4') 
        {
          velocity = 100;
        }
        else if (dataIn == '5') 
        {
          velocity = 125;
        }
        else if (dataIn == '6') 
        {
          velocity = 150;
        }
        else if (dataIn == '7') 
        {
          velocity = 175;
        }
        else if (dataIn == '8') 
        {
          velocity = 200;
        }
        else if (dataIn == '9') 
        {
          velocity = 225;
        }
        else if (dataIn == 'q') 
        {
          velocity = 255;
        }
        else if (dataIn == 'U') 
        {
          determinant = 'U';
        }
        else if (dataIn == 'u') 
        {
          determinant = 'u';
        }
        else if (dataIn == 'W') 
        {
          determinant = 'W';
        }
       
        else if (dataIn == 'w') 
        {
          determinant = 'w';
        }
  }
return determinant;
}

This is the code that won't compile

char dataIn = 'S';       //CharacterData coming from the phone.
int pinLeftTrackFB = 13;    //Pin controls left track bank forward and backward.
int pinRightTrackFB = 14;   //Pin controls right track bank forward and backward.
int BrakeLeftTrackFB = 8;   //Pin that enables/disables the left track bank.
int BrakeRightTrackFB = 15;  //Pin that enables/disables the right track bank
int pinLeftRightSpeed = 3;   //Pin that sets the speed for the Left-Right motor.
int pinLeftTrackSpeed = 11;   //Pin that sets the speed for the Left track bank.
int pinRightTrackSpeed = 16;  //Pin that sets the speed for the Right track bank.
int pinBrakeLeftTrackFB = 1;  //Pin that brakes left track.
int pinBrakeRightTrackFB = 2;  //Pin that brakes right track.
int pincamerapower = 4;    //Pin that activates power to front camera.
int pinlights = 7;   //Pin turns on led’s around tank.
char determinant;    //Used in the check function, stores the character received from the phone.
char det;    //Used in the loop function, stores the character received from the phone.
int velocity = 0;    //Stores the speed based on the character sent by phone.

void setup()
{
  //  NOTE: Once Bluetooth module is received find the Bluetooth unit number and put it in brackets of serial begin.
  Serial.begin(24634);   //Initialize serial communication with Bluetooth module at underlined number btu.
  pinMode(pinLeftTrackFB, OUTPUT);
  pinMode(pinRightTrackFB, OUTPUT);
  pinMode(pinBrakeLeftTrackFB, OUTPUT);
  pinMode(pinBrakeRightTrackFB, OUTPUT);
  pinMode(pinLeftRightSpeed, OUTPUT);
  pinMode(pinLeftTrackSpeed, OUTPUT);
  pinMode(pinRightTrackSpeed, OUTPUT);
  pinMode(pincamerapower, OUTPUT);
  pinMode(pinlights, OUTPUT);
}

void loop()
{
  det = check();
  while (det == 'F')  //If incoming data is an F, denotes the function move forward
  {
    digitalWrite(pinLeftTrackFB, LOW);
    digitalWrite(pinRightTrackFB, LOW);
    digitalWrite(pinBrakeLeftTrackFB, LOW);
    digitalWrite(pinBrakeRightTrackFB, LOW);
    analogWrite(pinLeftTrackFB, velocity);
    analogWrite(pinRightTrackFB, velocity);
    analogWrite(pinLeftTrackSpeed,255);
    analogWrite(pinRightTrackSpeed,255);
    det = check();
  }
  while (det == 'B')   //if incoming data is a B, move back
  {    
    digitalWrite(pinLeftTrackFB, HIGH);
    digitalWrite(pinRightTrackFB, HIGH);
    digitalWrite(pinBrakeLeftTrackFB, LOW);
    digitalWrite(pinBrakeRightTrackFB, LOW);
    analogWrite(pinLeftTrackFB, velocity);
    analogWrite(pinRightTrackFB, velocity);
    analogWrite(pinLeftTrackSpeed,-255);
    analogWrite(pinRightTrackSpeed,-255);
    det = check();          
  } 

  while (det == 'L')   //if incoming data is a L, move wheels left
  {     
    digitalWrite(pinLeftTrackFB, LOW);
    digitalWrite(pinRightTrackFB, HIGH);
    digitalWrite(pinBrakeLeftTrackFB, LOW);
    digitalWrite(pinBrakeRightTrackFB, LOW);
    analogWrite(pinLeftTrackFB, velocity);
    analogWrite(pinRightTrackFB, velocity);
    analogWrite(pinLeftTrackSpeed,0);
    analogWrite(pinRightTrackSpeed,255);
    det = check();          
  }  
  while (det == 'R')   //if incoming data is a R, move tank right
  {    
    digitalWrite(pinBrakeLeftTrackFB,HIGH);
    digitalWrite(pinBrakeRightTrackFB,LOW);
    analogWrite(pinLeftTrackFB, velocity);
    analogWrite(pinRightTrackFB, velocity);
    analogWrite(pinLeftTrackSpeed,255);
    analogWrite(pinRightTrackSpeed,0);
    det=check();
  }
  while (det == 'S')  //if incoming data is a S, stop
  {
    digitalWrite(pinLeftTrackFB, LOW);
    digitalWrite(pinRightTrackFB, LOW);
    analogWrite(pinLeftTrackSpeed,0);
    analogWrite(pinRightTrackSpeed,0);
    det = check();
  }
}

  int check()

    if (Serial.available() > 0)    //Check for data on the serial lines.
    {   
      dataIn = Serial.read();  //Get the character sent by the phone and store it in 'dataIn'.
      if (dataIn == 'F')
      {     
        determinant = 'F';
      }  
      else if (dataIn == 'B')
      { 
        determinant = 'B'; 
      }
      else if (dataIn == 'L')  
      { 
        determinant = 'L';
      }
      else if (dataIn == 'R')  
      { 
        determinant = 'R';
      } 
      else if (dataIn == 'I')  
      { 
        determinant = 'I'; 
      }  
      else if (dataIn == 'J')  
      {  
        determinant = 'J';
      }          
      else if (dataIn == 'G') 
      {
        determinant = 'G'; 
      }    
      else if (dataIn == 'H')  
      {
        determinant = 'H'; 
      }   
      else if (dataIn == 'S') 
      {
        determinant = 'S';
      }
      else if (dataIn == '0') 
      {
        velocity = 0;    //"velocity" does not need to be returned.
      }
      else if (dataIn == '1') 
      {
        velocity = 25;
      }
      else if (dataIn == '2') 
      {
        velocity = 50;
      }
      else if (dataIn == '3') 
      {
        velocity = 75;
      }
      else if (dataIn == '4') 
      {
        velocity = 100;
      }
      else if (dataIn == '5') 
      {
        velocity = 125;
      }
      else if (dataIn == '6') 
      {
        velocity = 150;
      }
      else if (dataIn == '7') 
      {
        velocity = 175;
      }
      else if (dataIn == '8') 
      {
        velocity = 200;
      }
      else if (dataIn == '9') 
      {
        velocity = 225;
      }
      else if (dataIn == 'q') 
      {
        velocity = 255;
      }
      else if (dataIn == 'U') 
      {
        determinant = 'U';
      }
      else if (dataIn == 'u') 
      {
        determinant = 'u';
      }
      else if (dataIn == 'W') 
      {
        determinant = 'W';
      }

      else if (dataIn == 'w') 
      {
        determinant = 'w';
      }
    }
  return determinant;
}

I’m having deja vu… didn’t we do this yesterday?

You have no opening brace here:

  }
}

  int check()
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    if (Serial.available() > 0)    //Check for data on the serial lines.
    {   
      dataIn = Serial.read();  //Get the character sent by the phone and store it in 'dataIn'.
      if (dataIn == 'F

But you have it here:

}

int check()
{ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  if (Serial.available() > 0)    //Check for data on the serial lines.
  {   
    dataIn = Serial.read();  //Get the character sent by the phone and store it in 'dataIn'.

Your fine tooth comb has a leak…

In your code, you have:

 int check()

    if (Serial.available() > 0)    //Check for data on the serial lines.

You need to add an opening parenthesis for the function block:

 int check()
{                        //   ---- Add this parenthesis
    if (Serial.available() > 0)    //Check for data on the serial lines.

You should also be able to simplify the huge cascading if statements, too.

Yeah I did ask this question and I did ask again. Its now fixed so thank you for the help

I wasn't seeing which one you were talking about, being frustrated didn't help, sorry for reasking the same question however in doing so it kinda made me realize where I was missing it so a very big thank you I owe you a tonne my system is now running :) Thanks for the help and sorry to be a royal pain in the a$$

Any help will be greatly

I would suggest a good textbook or online tutorial because at the moment you are floundering around randomly and have no idea what you are doing.