Pls Help me with this arduino code

Pls help me with this code. Compiling showing many error. Its a arduino 2 mode car. Bluetooth & auto mode using ultrasonic sensor.

// Arduino Robot Project: Dual function - 

//Library
#include "Ultrasonic.h"

//Constants
const int motorR1 = 2;
const int motorR2 = 3;
const int motorL1 = 4;
const int motorL2 = 5;

Ultrasonic ultrasonic(6,7); // Trig, Echo

//Variables
int distance=100;


int incomingData; 
char mode = 'm'; // m for manual, a for automatic
int vSpeed = 200; //default pwm value for motors speed

void setup(){
 //Define inputs and outputs
 pinMode(motorR1, OUTPUT);
 pinMode(motorR2, OUTPUT);
 pinMode(motorL1, OUTPUT);
 pinMode(motorL2, OUTPUT);
 
 
 //Start serial communication
 Serial.begin(9600);
}



void loop(){

 if(Serial.available() > 0){     
       // read the incoming byte:
       incomingData = Serial.read();
       if (incomingData == 'A'){mode = 'a'; }
       if (incomingData == 'M'){mode = 'm'; 
          stop();
          
       }  
    }

 //Change speed if incomingData is equal from 0 to 4. Values must be from 0 to 255 (PWM)
    if (incomingData == '0'){
      vSpeed=0;}
    else if (incomingData == '1'){
      vSpeed=100;}
    else if (incomingData == '2'){
      vSpeed=180;}
    else if (incomingData == '3'){
      vSpeed=200;}
    else if (incomingData == '4'){
      vSpeed=255;}
    
    //Manual mode
    if (mode == 'm'){
     if (incomingData=='F'){
     forward();
 }
     else if (incomingData=='B'){
     backward();
     }
     else if (incomingData=='R'){
     right();
     }
     else if (incomingData=='L'){
     left();
     }
     else if (incomingData=='S'){
     stop();
     }
    }
    //Automatic mode
    else if (mode == 'a'){
     distance = ultrasonic.Ranging(CM);
 
 //If an object detected at 5cm, stop the robot and find a way out
 if (distance <= 10){
    //robot stop
         stop();
  delay(500);

 //robot turns right
       right();
}
              else if (distance > 10){
  //robot moves forward
       forward();
}

 
}

//Movement functions

void forward(){
 analogWrite(motorR1, vSpeed);
 analogWrite(motorR2, 0);
 analogWrite(motorL1, vSpeed);
 analogWrite(motorL2, 0);
}

void backward(){
 analogWrite(motorR1, 0);
 analogWrite(motorR2, vSpeed);
 analogWrite(motorL1, 0);
 analogWrite(motorL2, vSpeed);
}

void right(){
 analogWrite(motorR1, 0);
 analogWrite(motorR2, vSpeed);
 analogWrite(motorL1, vSpeed);
 analogWrite(motorL2, 0);
}

void left(){
 analogWrite(motorR1, vSpeed);
 analogWrite(motorR2, 0);
 analogWrite(motorL1, 0);
 analogWrite(motorL2, vSpeed);
}

void stop(){
 analogWrite(motorR1, 0);
 analogWrite(motorR2, 0);
 analogWrite(motorL1, 0);
 analogWrite(motorL2, 0);
}
}

Compiling showing many error.

But your post isn't.

sp. "Please"

Suny94:
Pls help me with this code. Compiling showing many error.

Please post the error message

Look especially at the first error that is identified. Often fixing that will make the others go away.

...R

Errors

{facepalm}

Hint: nested functions are not allowed.

AWOL:
{facepalm}

Hint: nested functions are not allowed.

I am new on programmin. So please tell me detaile.

Many of the errors are because the functions forward(), left() etc are all defined inside loop(). Adding a } in the right place will fix that. If you did a Tools/AutoFormat (Ctrl-T) in the IDE that should have been obvious.

You also seem to be trying to use functions that aren't supported by the Ultrasonic library you've included.

Steve

Suny94:
Errors

Please don't post pictures of text. Just copy and paste the text.

And if you do post pictures please make them visible in your Post. See this Simple Image Guide

...R

slipstick:
Many of the errors are because the functions forward(), left() etc are all defined inside loop().

This looks like your best place to start working.

What you have now is

setup start
setup end

loop start
do things
call functions
function(s) start
function(s) end
loop end

What is being suggested is

setup start
setup end

loop start
do things
call functions
loop end

function(s) start
function(s) end