Merging Bluetooth initializer code with running code

Hi after a long struggle I have finally gotten both my bluetooth codes and running codes to run fine seperatly, however I am unsure as to how I would now merge these two codes together to get my system to work as a whole. I will add the codes below any help and advice would be much appreciated.
BT initializer code:

[code/*

/* Upload this sketch into Seeeduino and press reset*/
 
// old line: #include <NewSoftSerial.h>   //Software Serial Port
#include <SoftwareSerial.h>               //new line
#define RxD 3
#define TxD 2
 
#define DEBUG_ENABLED  1
 
// old line: NewSoftSerial blueToothSerial(RxD,TxD);
SoftwareSerial blueToothSerial(RxD,TxD);  //new line
 
void setup() 
{ 
  Serial.begin(38400);
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  setupBlueToothConnection();
 
} 
 
void loop() 
{ 
  char recvChar;
  while(1){
    if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
      recvChar = blueToothSerial.read();
      Serial.print(recvChar);
    }
    if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
      recvChar  = Serial.read();
      blueToothSerial.print(recvChar);
    }
  }
} 
 
void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable 
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}
]

RC running code:

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 pinfrontlights = 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(38400);   //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(pinfrontlights, 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();
  }
        
      while (det == 'W')   //if incoming data is a U, turn ON front lights
      {
          digitalWrite(pinfrontlights, HIGH);          
          det = check(); 
      }
      while (det == 'w')   //if incoming data is a u, turn OFF front lights
      {
          digitalWrite(pinfrontlights, 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;
}

Did you have a question? All I see is some code. Questions do NOT go in code blocks.

Oh oops accidently got the question inside my code box, my mistake, my question is what would be the first steps to merge these two codes, the first is an initializer for my bluetooth module the second is the code for my project, I'm not too good at merging codes together and I was just wondering if anyone could offer some support and advice on how to do it as smoothly and quickly as possible. Any and all help and feedback is appreciated.

This is not an actual answer to merging your two codes, but it is a cleaner way to gather the data to then control your other stuff.

Are you controlling this from a computer or better yet do you have control of what is being sent?

There is an encapsulation method(packet) that you can try. The sending data needs to be sent in this format < 1**,** 23**,** 456**,** . . . >. Not exactly how I have the values but it needs '<' a comma or some kind of separator and a '>'.

Note: This code convert a string of numeric chars into integers. However if you want to send the data another way, I would like to know.

If this goes over your head, I apologize, I can add in more comments if needed.

#define SOP '<'
#define EOP '>'
#define SPLIT ",>"

byte idx = 0, N_idx = 0;
boolean convert = false;
char c = NULL;
char * T_holder;
int * tmp = NULL;

#define MAXSIZE 20
char Data[ MAXSIZE ];
int buffer[ MAXSIZE ];
void setup()
{
  Serial.begin(115200);       
}

void loop() 
{
  tmp = getData(); // call the function to collect the incoming data and return a pointer to the collected data
  if(tmp)
  {
    for(byte i = 0; i < 5; i++)
      Serial.println(tmp[ i ]);
  }
}

int * getData()
{
  if( Serial.available() > 0)       // if data is available to read
  {
    c = Serial.read(); // read in the first character
    if(c == SOP) // compare that character to <
    {
      idx = 0;
      while( true ) // if the first char equals <, then collect the rest.
      {
        if( Serial.available() > 0) // this is needed again to make sure no junk is collected
        {
          c = Serial.read(); // read in the new chars

          if(c == EOP) // compare char to >
          {
            Data[ idx + 1 ] = EOP; // if char is equal to > then add it to the end of the packet
            convert = true; // tell the code to convert the chars to useable ints
            break; // break out of while loop
          }
          else
          {
            Data[ idx ] = c; // store new char in Data array
          }

          if(idx < MAXSIZE) // check to see the number of incoming chars does not exceed the set maximum
          {
            idx++; // number of char did not exceed the maximum chars allowed
          }
          else 
          {
            Serial.println("Input data has exceeded the maximum data allowed.");
            break;
          }
        }
      }
      
      if(convert == true)
      {
        clearBuffer(); // make sure the buffer is clean before adding to it

        T_holder = strtok(Data, SPLIT);// read the first data index, and store it in a temporary pointer
        buffer[ N_idx ] = atoi(T_holder); // convert the pointer to an integer

        while(T_holder != NULL) // convert the rest of the data until no more data can be read
        {
          N_idx++;
          T_holder = strtok(NULL, SPLIT); // search the data array for a comma, and >
          buffer[ N_idx ] = atoi(T_holder);
        }
        convert = false;
        return buffer; // when all data is converted, return it.
      }
    }
    else Serial.println("Incoming data must be formated as < ... >");
  } 
}

void clearBuffer()
{
  while(N_idx !=0)
  {
    buffer[N_idx] = 0; // cleans the buffer for new data.
    N_idx--;
  }
}

If you know exactly what your sending and exactly how many characters, you can reduce the code down more.

Hi I am controlling from a mobile phone, I have started merging the two but I have come up against and issue which I always have trouble with and although Im more or less certain that to fix it i need to add in a } im not exactly sure where, any help would be much appreciated

A loop that doesn't end inside another loop that doesn't end is usually not a good thing, nor needed.

This is your first code.

#include <SoftwareSerial.h>
#define RxD 3
#define TxD 2

const byte Led = 13;
#define DEBUG_ENABLED  1

// old line: NewSoftSerial blueToothSerial(RxD,TxD);
SoftwareSerial blueToothSerial(RxD,TxD);  
char recvChar; //declared globally. (Can be used throughout the code) 

void setup() 
{ 
  Serial.begin(115200); // much faster
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  pinMode(Led, OUTPUT);
  setupBlueToothConnection();
} 

void loop() 
{ 
  if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
    recvChar = blueToothSerial.read(); // what you get from here can be used throughout the code.
    Serial.print(recvChar);
  }
  if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
    recvChar  = Serial.read();
    blueToothSerial.print(recvChar);
  }

  if('1' == recvChar) 
    digitalWrite(Led, HIGH);
  else if('0' == recvChar)
    digitalWrite(Led, LOW);
} 

void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable 
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}

Hi so my real issue now is this, I am constantly having this problem and I am hopeless at fixing it as is proof from my other posts. I am coming up with this issue which is holding me back and have no idea where to put the closed bracket } For anyone who saw my other posts no it is not the same code its a different one with the same issue which I cannot figure out as I am a newbie.

/* Upload this sketch into Seeeduino and press reset*/
 
#include <SoftwareSerial.h>   //Software Serial Port
#define RxD 6
#define TxD 7
 
#define DEBUG_ENABLED  1
 
SoftwareSerial blueToothSerial(RxD,TxD);
 
void setup() 
{ 
  Serial.begin(9600);
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  setupBlueToothConnection();
 
} 
 
void loop() 
{ 
  char (det = check);
  while(1){
    if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
      (det = check) = blueToothSerial.read();
      Serial.print(det = check);
    }
    if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
      (det = check)  = Serial.read();
      blueToothSerial.print(det = check);
    }
  }
} 
 
void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable 
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}

Did you not learn anything from the code I gave you? Yes, I know you are new to this, but if you took the time to actually look and try the code I gave you, you would not be having your issue. (Of which has nothing to do with a missing closing bracket } )

BTW, it should be:
char det = check; // what is check, another variable?

No I did try it, just doesn't work for whatever reason with my module it doesn't allow it to become discoverable and a major issue with my bluetooth module is that it is very specific with the code it uses so its nothing against what you gave me its just it doesnt work with what I am using.

I didn't change anything with the bluetooth coding. Maybe change Serial.begin(115200) back to 9600.