expected primary-expression

I just started working on this micromouse project but I’m hitting an issue where it says primary expression is needed in my Echo function. I used this layout in another code but had only one sonic sensor. I need help with what’s going wrong. If you’re laughing at how I have a bunch of activities blocked out or not created yet, it’s because I’m using this code for testing stages then deleting what I don’t need in the end.

int trigF = 7;        //front sensor trigger
int echoF = 6;        //front sensor receive
int trigL =  9;        //Left sensor trigger
int echoL =  8;         //Left sensor receive
int trigR =  11;        //Right sensor trigger
int echoR =  10;         //Right sensor receive
int ledL =   12;        //status led for left sensor
int ledR =   13;          //status led for right sensor
int pwmL = 5;           // left motor PWM 500Hz with duty cycle control
int pwmR = 4;          // right motor PWM
int mtrLF = 2;         // Left motor forward direction
int mtrLR = 3;         // Left motor reverse direction
int mtrRF = 0;        // Right motor forward direction
int mtrRR = 1;         // Right motor reverse direction
int power = 0;

//functions (I need to figure out how to set up functions on here)

int Straight(int power) //Moving straight
{
  Left(power);
  Right(power);
}
/*
void Reverse (power) //moving backwards //might not be used
{
  LeftReverse(power)
  RightReverse(power)
}
*/
int Left(int power)  //Left motor forward
{
  analogWrite(pwmL, power);   // controls 500Hz PWM waveform duty cycle 0-255, 127=50% DC therefore 1/2 speed. note never run motors below 50% duty cycle
  digitalWrite(mtrLF, HIGH);   // controls mtr direction
  digitalWrite(mtrLR, LOW); // controls mtr direction
}
int LeftReverse(int power) //Left motor backwards
{
  analogWrite(pwmL, power);   // controls 500Hz PWM waveform duty cycle 0-255, 127=50% DC therefore 1/2 speed. note never run motors below 50% duty cycle
  digitalWrite(mtrLF, LOW);   // controls mtr direction
  digitalWrite(mtrLR, HIGH); // controls mtr direction
}
int Right(int power) //Right motor forward
{
  analogWrite(pwmR, power);   // controls 500Hz PWM waveform duty cycle 0-255, 127=50% DC therefore 1/2 speed. note never run motors below 50% duty cycle
  digitalWrite(mtrRF, HIGH);   // controls mtr direction
  digitalWrite(mtrRR, LOW); // controls mtr direction
}
int RightReverse(int power)//Right Motor Backwards
{
  analogWrite(pwmR, power);   // controls 500Hz PWM waveform duty cycle 0-255, 127=50% DC therefore 1/2 speed. note never run motors below 50% duty cycle
  digitalWrite(mtrRF, LOW);   // controls mtr direction
  digitalWrite(mtrRR, HIGH); // controls mtr direction
}
int Echo //send and receive echo pulse
{
  long durationF, distanceF;
  long durationL, distanceL;
  long durationR, distanceR;
  digitalWrite(trigF, LOW);
  digitalWrite(trigL, LOW);
  digitalWrite(trigR, LOW);
  delayMicroseconds(2);
  digitalWrite(trigF, HIGH);
  digitalWrite(trigL, HIGH);
  digitalWrite(trigR, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigF, LOW);
  digitalWrite(trigL, LOW);
  digitalWrite(trigR, LOW);
  durationF = pulseIn(echoF, HIGH);
  distanceF = (durationF/2)/29.1;
  durationL = pulseIn(echoL, HIGH);
  distanceL = (durationL/2)/29.1;
  durationR = pulseIn(echoR, HIGH);
  distanceR = (durationR/2)/29.1;
}



void setup() {
  pinMode(trigF, OUTPUT);
  pinMode(echoF, INPUT);
  pinMode(trigL, OUTPUT);
  pinMode(echoL, INPUT);
  pinMode(trigR, OUTPUT);
  pinMode(echoR, INPUT);
  pinMode(ledL, OUTPUT);
  pinMode(pwmL, OUTPUT);    //PWM to H Bridge
  pinMode(pwmR, OUTPUT);
  pinMode(mtrLF, OUTPUT);   // fwd signal to H Bridge
  pinMode(mtrLR, OUTPUT);   // Rev signal to H Bridge
  pinMode(mtrRF, OUTPUT);
  pinMode(mtrRR, OUTPUT);
}


void loop() {
//first setup left lover. (mouse will turn left at every left opening and if it comes to dead end it will turn around 360 degrees and continue looking for left openings).  
  echo;
  
  if(distanceL>50)//mouse has found a doorway on the left side
  {
    Left(0);
    Right(150);
  }
  else if (distanceF>50)//mouse has not found a doorway on the left
  {
    straight;
  }
  else //mouse came to dead end or there is only an opening on the right (turn around 180 degrees)
  {
    Left(150);
    RightReverse(150);
    delayMicroseconds (3000);
    Left(150);
    Right(150);
  }

/*
//second setup right lover. (mouse will turn right at every right opening and if it comes to dead end it will turn around and continue looking for right openings). 
  echo;
  
  if(distanceL>50)//mouse has found a doorway on the left side
  {
    Left(150);
    Right(0);
  }
  else if (distanceF>50)//mouse has not found a doorway on the left
  {
    straight;
  }
  else //mouse came to dead end or there is only an opening on the right
  {
    Left(150);
    RightReverse(150);
    delayMicroseconds (3000);
  }
  delayMicroseconds (500); //Gibe time for the bot to move to next square and calculate what it sees
*/

/*
//Third setup array storage. (mouse will store opening data in numbers of 0 and 1, o means no opening, 1 means an opening. If the bot comes to dead end the bot will turn around 180 degrees and reverse the array also making what was on the left on the right.
//When the bot is going backwars with the array it will go back into original feed when the bot finds an opening it has not been to yet. This code will hold 3 arrays that are 256 units long one for each side, or else store every opening setup as a number ->
//EX. : no openings 0, opening in front 1, opening on left 2, opening on right 3, opening on left and front 4, opening on right and front 5, opening on left and right 6, opening on left right and front 7. Disadvantage to this there will be no way for the ->
//bot to calculate the fastest return path.) 

*/

/*
//Final setup flood. (the maze will be setup with numbers starting at 8 then the center of the maze is 0. A disadvantage to this like the array storage would be that a lot of memory will need to be used.
*/
  delayMicroseconds (500); //Give time for the bot to move to next square and calculate what it sees
}

In the following code the line I’m asking for help with actually worked. I’m wondering if it’s because of how I put the action in a function.

int trigPin = 13;
int echoPin = 12;
int Red = 11;
int Green = 10;
int led13 = 13;           // status LED for motor direction
int mtr = 10;           // motor PWM 500Hz with duty cycle control
int mtrF = 2;         // motor forward direction
int mtrR = 4;         // motor reverse direction

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(Red, OUTPUT);
  pinMode(Green, OUTPUT);
  pinMode(led13, OUTPUT);    // amber Status LED on UNO board
  pinMode(mtr, OUTPUT);   //PWM to H Bridge
  pinMode(mtrF, OUTPUT);    // fwd signal to H Bridge
  pinMode(mtrR, OUTPUT);   // Rev signal to H Bridge
}

void loop() {

  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2)/29.1;
  if(distance<20){
  analogWrite(mtr, 127);   // controls 500Hz PWM waveform duty cycle 0-255, 127=50% DC therefore 1/2 speed
   // note never run motors below 50% duty cycle
  digitalWrite(mtrF, LOW);   // controls mtr direction
  digitalWrite(mtrR, LOW); // controls mtr direction
  digitalWrite(led13, HIGH); // controls LED 13 on UNO board
  }
  else{
   analogWrite(mtr, 222);   // controls 500Hz PWM waveform duty cycle 0-255, 127=50% DC
  digitalWrite(mtrF, HIGH);   // controls mtr direction
  digitalWrite(mtrR, LOW); // controls mtr direction
  digitalWrite(led13, LOW); // controls LED 13 on UNO board
  }
  

}

This is my first time posting on this forum so I’m sorry if there are any errors.

[quote author=Ian Oberdorf link=msg=3246646 date=1493859234] I just started working on this micromouse project but I'm hitting an issue where it says primary expression is needed in my Echo function.

[/quote]

That's not what it says. It also gives the line number where it found the error and it gives the text of what it expected a primary expression before. Why don't you post the actual error message text so someone can try to find it.

int Echo //send and receive echo pulse
{

Look carefully at that function definition. Are you missing something?

This code is not going to work well. If you pulse the Trigger pin on all three ultrasonic range finders nearly simultaneously you will not only have cross-talk between units (receiving an echo of a different unit's pulse) you will not be able to measure all three echo pulses at the same time. The first pulseIn() call will not return until the pulse ends... by which time it is probably too late to catch the beginning of either of the other two pulses.

The NewPing library provides an example for sampling 15 ultrasonic sensors at 30 millisecond intervals. You can reduce that to three sensors easily.

{
  long durationF, distanceF;
  long durationL, distanceL;
  long durationR, distanceR;
  digitalWrite(trigF, LOW);
  digitalWrite(trigL, LOW);
  digitalWrite(trigR, LOW);
  delayMicroseconds(2);
  digitalWrite(trigF, HIGH);
  digitalWrite(trigL, HIGH);
  digitalWrite(trigR, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigF, LOW);
  digitalWrite(trigL, LOW);
  digitalWrite(trigR, LOW);
  durationF = pulseIn(echoF, HIGH);
  distanceF = (durationF/2)/29.1;
  durationL = pulseIn(echoL, HIGH);
  distanceL = (durationL/2)/29.1;
  durationR = pulseIn(echoR, HIGH);
  distanceR = (durationR/2)/29.1;
}