A function-definition is not allowed here before '{' token

"Hi i need your help with my code I don't know what i did wrong, but for some reason i am getting an error message saying a function-definition is not allowed here before '{' token this code is suppose to run rc car through pc using arduino mega 2560, please can you help me anyone, i have tried everything. :frowning:

int forward = 30; // Pin 12 - Forward
int reverse = 40; // Pin 11 - Reverse
int left = 51; // Pin 10 - Left
int right = 39; // Pin 9 - Right

char val; // Variable to receive data from the serial port

void setup() {

// initialize the digital pins as output
pinMode(forward, OUTPUT);
pinMode(reverse, OUTPUT);
pinMode(left, OUTPUT);
pinMode(right, OUTPUT); Serial.begin(9600); // Start serial communication at 9600bps
}


// Fordward action
void go_forward() {
digitalWrite(forward, HIGH);
digitalWrite(reverse, LOW);
}

// Reverse action
void go_reverse() {
digitalWrite(reverse, HIGH);
digitalWrite(forward, LOW);
}


// Left action
void go_left() {
digitalWrite(left, HIGH);
digitalWrite(right, LOW);
}

// Right action
void go_right() {
digitalWrite(right, HIGH);
digitalWrite(left, LOW);
}

// Stop turn action
void stop_turn() {
digitalWrite(right, LOW);
digitalWrite(left, LOW);
}

// Stop car
void stop_car() {
digitalWrite(forward, LOW);
digitalWrite(reverse, LOW);
digitalWrite(right, LOW);
digitalWrite(left, LOW);
}

// Read serial port and perform command
void performCommand() {
if (Serial.available()) { val = Serial.read();
} if (val == 'w') { // Forward go_forward(); } else if (val == 's') { // Backward go_reverse(); } else if (val == 'd') { // Right go_right(); } else if (val == 'a') { // Left go_left(); } else if (val == 'l') { // Stop Turn stop_turn(); } else if (val == 'k') { // Stop stop_car(); }
}


void loop() {
performCommand();
}

Arduino Software Error messages:

sketch_sep05a.ino: In function 'void performCommand () ' :
sketch_sep05a: 64: error: a function-definition is not allowed
here before ' { ' token
sketch_sep05a:66: error: expected ' } ' at end of input
a function-definition is not allowed here before ' { ' token

Your bizarre formatting of void performCommand() is not helping you to see the problem which is the fact that the // comments are eliminating the closing braces in all your conditionals.

// Read serial port and perform command
void performCommand() {
  if (Serial.available()) {
    val = Serial.read();
  }
  if (val == 'w')
  { // Forward go_forward();
  }
  else if (val == 's')
  { // Backward go_reverse();
  }
  else if (val == 'd')
  { // Right go_right();
  }
  else if (val == 'a')
  { // Left go_left();
  }
  else if (val == 'l')
  { // Stop Turn stop_turn();
  }
  else if (val == 'k')
  { // Stop stop_car();
  }
}

I think it's a problem with braces being in wrong place. Probably should look something like this:

int forward = 30; // Pin 12 - Forward
int reverse = 40; // Pin 11 - Reverse
int left = 51; // Pin 10 - Left
int right = 39; // Pin 9 - Right

char val; // Variable to receive data from the serial port

void setup() {

// initialize the digital pins as output
pinMode(forward, OUTPUT);
pinMode(reverse, OUTPUT);
pinMode(left, OUTPUT);
pinMode(right, OUTPUT); Serial.begin(9600); // Start serial communication at 9600bps
}


// Fordward action
void go_forward() {
digitalWrite(forward, HIGH);
digitalWrite(reverse, LOW);
}

// Reverse action
void go_reverse() {
digitalWrite(reverse, HIGH);
digitalWrite(forward, LOW);
}


// Left action
void go_left() {
digitalWrite(left, HIGH);
digitalWrite(right, LOW);
}

// Right action
void go_right() {
digitalWrite(right, HIGH);
digitalWrite(left, LOW);
}

// Stop turn action
void stop_turn() {
digitalWrite(right, LOW);
digitalWrite(left, LOW);
}

// Stop car
void stop_car() {
digitalWrite(forward, LOW);
digitalWrite(reverse, LOW);
digitalWrite(right, LOW);
digitalWrite(left, LOW);
}

// Read serial port and perform command
void performCommand() {
if (Serial.available()) {val = Serial.read(); 

if (val == 'w') { 
    //Forward
    go_forward(); 
  } else if (val == 's') {
    //Backward 
    go_reverse(); 
  } else if (val == 'd') {  
    //Right 
    go_right(); 
  } else if (val == 'a') {
    //Left 
    go_left();
  } else if (val == 'l') {
    //Stop Turn
    stop_turn(); 
  } else if (val == 'k') { 
    //Stop 
    stop_car(); 
  }
}}


void loop() {
performCommand();
}

Thank you very much, you guys were right the braces were not separated with each time i commented on the new condition under void performCommand() I very much appreciate it you guys thanks very much.

Rupersero:
I think it's a problem with braces being in wrong place. Probably should look something like this:

int forward = 30; // Pin 12 - Forward

int reverse = 40; // Pin 11 - Reverse
int left = 51; // Pin 10 - Left
int right = 39; // Pin 9 - Right

char val; // Variable to receive data from the serial port

void setup() {

// initialize the digital pins as output
pinMode(forward, OUTPUT);
pinMode(reverse, OUTPUT);
pinMode(left, OUTPUT);
pinMode(right, OUTPUT); Serial.begin(9600); // Start serial communication at 9600bps
}

// Fordward action
void go_forward() {
digitalWrite(forward, HIGH);
digitalWrite(reverse, LOW);
}

// Reverse action
void go_reverse() {
digitalWrite(reverse, HIGH);
digitalWrite(forward, LOW);
}

// Left action
void go_left() {
digitalWrite(left, HIGH);
digitalWrite(right, LOW);
}

// Right action
void go_right() {
digitalWrite(right, HIGH);
digitalWrite(left, LOW);
}

// Stop turn action
void stop_turn() {
digitalWrite(right, LOW);
digitalWrite(left, LOW);
}

// Stop car
void stop_car() {
digitalWrite(forward, LOW);
digitalWrite(reverse, LOW);
digitalWrite(right, LOW);
digitalWrite(left, LOW);
}

// Read serial port and perform command
void performCommand() {
if (Serial.available()) {val = Serial.read();

if (val == 'w') {
   //Forward
   go_forward();
 } else if (val == 's') {
   //Backward
   go_reverse();
 } else if (val == 'd') {  
   //Right
   go_right();
 } else if (val == 'a') {
   //Left
   go_left();
 } else if (val == 'l') {
   //Stop Turn
   stop_turn();
 } else if (val == 'k') {
   //Stop
   stop_car();
 }
}}

void loop() {
performCommand();
}

Help me :frowning:

Project_2.ino (13.5 KB)

You REALLY need to learn where { and } and needed, and where they are not.

Where does your setup() function end?

And proper code indentation can really help you see that. And a general rule, NOTHING follows a {, } or ; (expect in a loop declaration). Then, press Ctrl+T.

Hello,
Please does anyone know what's wrong with this code, i get the message 'A function-definition is not allowed here before '{' token' for the 2nd void loop

void loop() {

if(bt.available()) {
char databt=bt.read(); // byte

if(databt=='a') {

void loop()
{
repeat2:
delay(1000);
databt=bt.read();
val=analogRead(ldr),a=digitalRead(boutton);
delay(500);

if(databt=='b') {
goto repeat1;
}

if(databt=='1') {
digitalWrite(led1,1);
bt.println("led1 ON "); }

if(databt=='2') {
digitalWrite(led2,1);
bt.println("led2 ON "); }

if(databt=='3') {
digitalWrite(led3,1);
bt.println("led3 ON "); }

if(databt=='4') {
digitalWrite(led1,0);
bt.println("led1 ON "); }

if(databt=='5') {
digitalWrite(led2,0);
bt.println("led2 ON "); }

if(databt=='6') {
digitalWrite(led3,0);
bt.println("led3 ON "); }

if(databt=='7') {
digitalWrite(led3,1);
digitalWrite(led1,1);
digitalWrite(led2,0);
bt.println("leds ON "); }

if(databt=='0') {
digitalWrite(led1,0),digitalWrite(led2,0),digitalWrite(led3,0);
bt.println("leds OFF "); }

delay(1000);

if(val<400 && a==1) // dalma
{
digitalWrite(lamp2jardin,1),digitalWrite(lamp1jardin,1);
digitalWrite(buzzer,1);
Serial.println(" detection mouvement ");
delay(100);
}
if(val>=400 && a==1) { // benhar
digitalWrite(lamp2jardin,0),digitalWrite(lamp1jardin,0);
digitalWrite(buzzer,1);
Serial.println(" detection mouvement ");
delay(100);
}
if(val<400 && a==0) {
digitalWrite(lamp1jardin,1),digitalWrite(lamp2jardin,1);
digitalWrite(buzzer,0);
delay(500); }

if(val>=400 && a==0) {
digitalWrite(lamp1jardin,0), digitalWrite(lamp2jardin,0);
digitalWrite(buzzer,0);
delay(100); }
}
}

the 2nd void loop

How many loop functions in an Arduino sketch?

(Hint: if there's more than one, how does the compiler know which to execute?)

Also please remember to use code tags when posting code

Welcome to forum. Please use code tags to post your code! It is all described in sticky threads at the top.
"How to use this forum - please read."

There is a very good tool in the IDE. Autoformat - shortcut is Ctrl-T.

I can see errors from the first few lines of your code. Two void loop(), and the first have 3 opening brackets and no closing bracket. It should only be one loop and every { need a corresponding }.

void loop()    {
  
  if(bt.available())  {
  char databt=bt.read();         // byte

  if(databt=='a')  {
  
   void loop()    
   {

well... I have the same problem with the definition that is not allowed. Can you please help me?

TransmitterCode.ino (1.67 KB)

alvaroanavarro1:
Can you please help me?

Can you post your code?

This is not how a function looks like

void transmitting(); //function aux

This could be a function, if it wasn't put inside void loop()

  void transmitting() {
    if ( c == '1')
      vw_send((uint8_t *)c, 1);
    else if (c == '0')
      vw_send((uint8_t *)c, 0);
  }

}

You have used autoformat - it is great. It lets you see that void transmitting() { isn't placed at leftmost position as it should be.
You are missing a closing bracket for void loop() and you got an extra at the end. You need to move it above transmitting and remove the faulty function at top.

This is not how a function looks like

It's what a function prototype looks like, though, so it is perfectly valid.

sahoosk:
Dear Respected Sirs

Namaskar.

I am sksahoo from India has written a code which is giving some errors.
i am posting the code here. Please help to solve the issues.

i will be thankfull.

code:

#define RL1Pin  4

#define RL2Pin  5
#define RL3Pin  6
#define RL4Pin  7
#define ledPin  8  // led for indication of timer
#define swPin  9

#define lowLimit  80
#define highLimit  250
#define lowOk  90
#define highOk  220

float m;
float n;
float mainV = 0;

unsigned int step=1;
unsigned int time=0,x;
int fault=0;
unsigned int rDelayTime=30;

/*********************************************************/
void setup() {
  pinMode (A0, INPUT);
  pinMode (RL1Pin, OUTPUT);
  pinMode (RL2Pin, OUTPUT);
  pinMode (RL3Pin, OUTPUT);
  pinMode (RL4Pin, OUTPUT);

pinMode (ledPin, OUTPUT);
  pinMode (swPin, INPUT);
  Serial.begin (9600);
}
/********************************************************/

void loop () {
  initialise ();

while (1) {
        startUp ();
      do
      {
        for (x=0: x<20; x++) {
          readAdc ();
        }
      }
 
  if (mainV >241) {
    step--;
    if (step<1) step--;
  }
  else if (mainV<90) {
    step++;
    if (step>6) step=6;
  }
    relaySet ();
  } 
while ((mainV>highLimit) && (mainV<lowLimit));
    fault = 1;
    rDelayTime = 0;
   
    if (mainV>=highLimit) mainHigh ();
        else if (mainV<=lowLimit); mainLow ();
      fault=0;
    }
}

/Initialize Function****/

void initialise () {
  digitalWrite ( RL4Pin, LOW);
    digitalWrite (RL1Pin, HIGH);
    digitalWrite (RL2Pin, HIGH);
      digitalWrite (RL3Pin, HIGH);
}

/StartUp Function*************/

void startUp () {
  delay (100);
  readAdc ();
  delay (1000*25);
}

/readAdc Function***********/

void readAdc() {
  m = analogRead (A0);
  n = (m*0.304177);
  Serial.print ("Analog Value");
  Serial.print (m);
  Serial.print ("  AC Voltage  ");
  mainV = (n/sqrt(2));
  Serial.print (mainV);
  Serial.println ();
  delay (1000);
}

/mainHigh Function*****************/

void mainHigh() {
  digitalWrite (RL4Pin, LOW);
  digitalWrite (RL3Pin, HIGH);
    digitalWrite (RL2Pin, HIGH);
    digitalWrite (RL1Pin, HIGH);
      delay (500);
    while (mainV >= highOk) {
      rDelayTime = 0;
      readAdc ();
    }
     
  }

/mainLow Function****************/

void mainLow () {
  digitalWrite (RL4Pin, LOW);
    digitalWrite (RL3Pin, LOW);
    digitalWrite (RL2Pin, LOW);
      digitalWrite (RL1Pin, LOW);
      delay (500);

while (mainV = lowOk) {
        rDelayTime = 0;
          readAdc ();
      }
  }

/relaySet Function************/

void relaySet () {
  if (step==1) {
    digitalWrite (RL1Pin,1);
    digitalWrite (RL2Pin,1);
    digitalWrite (RL3Pin,1);
  }
  else if (step==2) {
    digitalWrite (RL1Pin,1);
    digitalWrite (RL2Pin,1);
    digitalWrite (RL3Pin,0);
  }
  else if (step==3) {
    digitalWrite (RL1Pin,1);
    digitalWrite (RL2Pin,0);
    digitalWrite (RL3Pin,1);
  }
  else if (step==4) {
    digitalWrite (RL1Pin,1);
    digitalWrite (RL2Pin,0);
    digitalWrite (RL3Pin,0);
  }
  else if (step==5) {
    digitalWrite (RL1Pin,0);
    digitalWrite (RL2Pin,0);
    digitalWrite (RL3Pin,1);
  }
  else if (step==6) {
    digitalWrite (RL1Pin,0);
    digitalWrite (RL2Pin,0);
    digitalWrite (RL3Pin,0); }
    else {
}

/*******************************************/

Use code tags, see how to use forum thread if you dont know how. Use ctrl+T in ide to autoformat - this make many mistakes with braces very obvious

You are missing a } to close the last function

In at least one place you have something like

else if (...); doSomething();

This is wrong. You do not put a ; between the ) after the test in an if or while statement, and the code to execute if the test is true. If/while executes the next statement or block conditionally. A ; alone is an empty statement, so the example i gave above, doSomething() is called regardless of the test!

//Call the custom settings to optimize the flash memory usage
#define CUSTOM_SETTINGS
//Calling for Arduino Voice Recognize Shield
#define INCLUDE_VOICE_RECOGNIZER_SHIELD

//Including 1Sheeld library
#include <OneSheeld.h>
#include <Stepper.h>

int level=0;

//Set commands to be recognized by the Arduino Voice Recognition Shield
const char levelzeroCommand[] = "level zero";
const char leveloneCommand[] = "level one";
const char leveltwoCommand[] = "level two";

const int stepsPerRevolution = 256; // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper1(stepsPerRevolution, 4, 6, 5, 7);
Stepper myStepper2(stepsPerRevolution, 4, 6, 5, 7);
Stepper myStepper3(stepsPerRevolution, 4, 6, 5, 7);
Stepper myStepper4(stepsPerRevolution, 4, 6, 5, 7);

void setup() {
// set the speed at 60 rpm:
myStepper1.setSpeed(60);
myStepper2.setSpeed(60);
myStepper3.setSpeed(60);
myStepper4.setSpeed(60);

void setup ()
{
//Initialize the communication between 1Sheeld's Arduino Voice Recognition Shield and Arduino
OneSheeld.begin();

void loop ()

//check if 1Sheeld's Arduino Voice Recognition Shield received a new command
if(VoiceRecognition.isNewCommandReceived())
{
//Compare the last command received by the Arduino Voice Recognition Shield with the command "on"
if(!strcmp(levelzeroCommand ,VoiceRecognition.getLastCommand()))
{
//Then turn the light on
if (millis()<8000) {

myStepper1.step(1);
myStepper2.step(1);
myStepper3.step(-1);
myStepper4.step(-1);
}
}
//Compare the last command received by the Arduino Voice Recognition Shield with the command "off"
if(!strcmp(levelzeroCommandtwo,VoiceRecognition.getLastCommand()))
{
//Then turn the light off
if (millis()<8000) {

myStepper1.step(1);
myStepper2.step(1);
myStepper3.step(-1);
myStepper4.step(-1);
}
}

{
//Then turn the light off
if (millis()<8000) {

myStepper1.step(1);
myStepper2.step(1);
myStepper3.step(-1);
myStepper4.step(-1);
}
}
}
}

void setup() {
  // set the speed at 60 rpm:
  myStepper1.setSpeed(60);
  myStepper2.setSpeed(60);
  myStepper3.setSpeed(60);
  myStepper4.setSpeed(60);


void setup ()

Oops.

void setup () 
{
  //Initialize the communication between 1Sheeld's Arduino Voice Recognition Shield and Arduino
  OneSheeld.begin();
  


void loop ()

  //check if 1Sheeld's Arduino Voice Recognition

Double oops

Please remember to use code tags when posting code.

having the same error message.
some help please or give some directions

// Imports
#include <Servo.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
#include <Servo.h>
#include <TinyGPS++.h>
//#include <TinyGPS.h>


// Bluetooth GPS input
#define SOP '<'
#define EOP '>'


// You must then add your 'Declination Angle' to the compass, which is the 'Error' of the magnetic field in your location.
// Find yours here: http://www.magnetic-declination.com/
// Mine is: 23° 4' E (Positive),
#define DECLINATION_ANGLE +0.34f


#define COMPASS_OFFSET 0.35f


#define GPS_UPDATE_INTERVAL 1000


#define GPS_WAYPOINT_TIMEOUT 25

// Struct to combine our coordinates into one struct for ease of use
struct GeoLoc {
  float lat;
  float lon;
};
float lat, lon;
// GPS
//TinyGPS gps;
TinyGPSPlus gps;
#define GPS_BAUD 9600

// servomotor
Servo myservo;

// Master Enable
bool enabled = true;

// Bluetooth input
bool started = false;
bool ended = false;
char inData[80]; // creates an 80 character array called "inData"
byte index; //creates a variable type=byte called "index"
double Long; //variable for longitude coordinate
double Lat; //variable for latitude coordinate


/* Compass */
Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);

GeoLoc checkGPS() {
  Serial.println("Reading onboard GPS: ");
  Serial2.begin(9600); // connect gps sensor
  unsigned long start = millis();
  while (millis() - start < GPS_UPDATE_INTERVAL) {
    // If we recieved new location then take the coordinates and pack them into a struct
    if (feedgps())
      return gpsdump();
  }

  GeoLoc robotLoc;
  robotLoc.lat = 0.0;
  robotLoc.lon = 0.0;

  return robotLoc;
}

// Get and process GPS data
GeoLoc gpsdump() {
  GeoLoc robotLoc;
  robotLoc.lat = gps.location.lat();
  robotLoc.lon = gps.location.lng();

  Serial.print("Position: ");

  //Latitude
  Serial.print("Latitude: ");
  Serial.print(lat, 7);

  Serial.print(",");

  //Longitude
  Serial.print("Longitude: ");
  Serial.println(lon, 7);
  return robotLoc;
}

// Feed data as it becomes available
bool feedgps() {
  while (Serial2.available() > 0) {
    if (gps.encode(Serial2.read()))
      return true;
  }
  return false;
}

void displayCompassDetails(void)
{
  sensor_t sensor;
  mag.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" uT");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" uT");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" uT");
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

#ifndef DEGTORAD
#define DEGTORAD 0.0174532925199432957f
#define RADTODEG 57.295779513082320876f
#endif

float geoBearing(struct GeoLoc &a, struct GeoLoc &b) {
  float y = sin(b.lon - a.lon) * cos(b.lat);
  float x = cos(a.lat) * sin(b.lat) - sin(a.lat) * cos(b.lat) * cos(b.lon - a.lon);
  return atan2(y, x) * RADTODEG;
}

float geoDistance(struct GeoLoc &a, struct GeoLoc &b) {
  const float R = 6371000; // radius of earth in metres
  float p1 = a.lat * DEGTORAD;
  float p2 = b.lat * DEGTORAD;
  float dp = (b.lat - a.lat) * DEGTORAD;
  float dl = (b.lon - a.lon) * DEGTORAD;

  float x = sin(dp / 2) * sin(dp / 2) + cos(p1) * cos(p2) * sin(dl / 2) * sin(dl / 2);
  float y = 2 * atan2(sqrt(x), sqrt(1 - x));

  // returns distance in meters
  return R * y;
}

float geoHeading() {
  /* Get a new sensor event */
  sensors_event_t event;
  mag.getEvent(&event);


  float heading = atan2(event.magnetic.y, event.magnetic.x);

  // Offset
  heading -= DECLINATION_ANGLE;
  heading -= COMPASS_OFFSET;


  if (heading < 0)
    heading += 2 * PI;


  if (heading > 2 * PI)
    heading -= 2 * PI;


  float headingDegrees = heading * 180 / M_PI;

  // Map to -180 - 180
  while (headingDegrees < -180) headingDegrees += 360;
  while (headingDegrees >  180) headingDegrees -= 360;

  return headingDegrees;
}



void controlservo(int direction)
{ int headingAngle;
  float headingDegrees;
  headingAngle = headingDegrees;
  if (headingAngle == 0) {
    myservo.write(90);
  }
  else if (headingAngle == headingDegrees) {
    myservo.write(headingDegrees);
  }
}



void driveTo(struct GeoLoc &loc, int timeout) {
  Serial2.read();
  GeoLoc robotLoc = checkGPS();
  Serial1.read();

  if (robotLoc.lat != 0 && robotLoc.lon != 0 && enabled) {
    float distance = 0;
    //Start move loop here
    do {
      Serial2.read();
      robotLoc = checkGPS();
      Serial1.read();

      distance = geoDistance(robotLoc, loc);
      float bearing = geoBearing(robotLoc, loc) - geoHeading();

      Serial.print("Distance: ");
      Serial.println(distance);

      Serial.print("Bearing: ");
      Serial.println(geoBearing(robotLoc, loc));

      Serial.print("Heading: ");
      Serial.println(geoHeading());


    }
    while (distance > 1.0 && enabled && timeout > 0);


  }
}

void setupCompass() {
  /* Initialise the compass */
  if (!mag.begin())
  {
    /* There was a problem detecting the HMC5883 ... check your connections */
    Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");
    while (1);
  }

  /* Display some basic information on this sensor */
  displayCompassDetails();
}

void setup()
{
  // Attaching servo
  myservo.attach(13);



  //Debugging via serial
  Serial.begin(115200);

  // Compass
  setupCompass();

  //GPS
  Serial2.begin(GPS_BAUD);

  {
    Serial.begin(9600);
    Serial1.begin(38400);
    Serial.println("ATcommand");  //ATcommand Start


  }

  void loop(){
    //Blynk.run();
    // Read all serial data available, as fast as possible
    //while (Serial1.available() > 0)
    while (Serial1.available())
    {
      char inChar = ((byte)Serial1.read());
      if (inChar == SOP)
      {
        index = 0;
        inData[index] = '\0';
        started = true;
        ended = false;
      }
      else if (inChar == EOP)
      {
        ended = true;
        break;
      }
      else
      {
        if (index < 79)
        {
          inData[index] = inChar;
          index++;
          inData[index] = '\0';
        }
      }
    }
  }
}

 
  if (started && ended)
  {
    char *token = strtok(inData, ",");
    boolean first = true;
    while (token)
    {
      double val = atof(token);
      token = strtok(NULL, ",");
      if (first) {
        Lat = val;
      } else {
        Long = val;
      }
      first = false;
    }

    // Reset for the next packet
    started = false;
    ended = false;
    index = 0;
    inData[index] = '\0';

    GeoLoc waypointLoc;
    waypointLoc.lat = Lat;
    waypointLoc.lon = Long;

    Serial.print(waypointLoc.lat, 7); Serial.print(", "); Serial.println(waypointLoc.lon, 7);
    driveTo(waypointLoc, GPS_WAYPOINT_TIMEOUT);

  }
}

Since that's not the same code I can guarantee that you're not getting the same error message. If you want help post the COMPLETE error message. It contains lots of useful information.

And use AutoFormat (Ctrl-T) in the IDE. That should help you see where you're going wrong, like having braces { } in random places. Check that each function finishes where you think it should and that all code is inside a function.

Steve

@alexmunala

Other post/duplicate DELETED
Please do NOT cross posts / duplicates as it wastes peoples time and efforts to have more than one post for a single topic.

Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.