Error: expected unqualified-id before '{' token exit status 1 Compilation error: expected unqualified-id before '{' token

I have this code but that error appears on 80th line, what's wrong?

#include <SoftwareSerial.h>
SoftwareSerial BT(4,2); // RX, TX recorder que se cruzan

#include <NewPing.h>
#define PIN_TRIG 12   // Pin del Arduino conectado al pin Trigger del sensor de ultrasonidos
#define PIN_ECHO 13   // Pin del Arduino conectado al pin Echo del sensor de ultrasonidos
#define MAX_DISTANCIA 100  // Distancia máxima a detectar en cm.
NewPing sonar(PIN_TRIG, PIN_ECHO, MAX_DISTANCIA);

// Motor 1
int ENA = 10;
int IN1 = 9;
int IN2 = 8;

// Motor 2
int ENB = 5;
int IN3 = 7;
int IN4 = 6;

void setup() {
 Serial.begin(9600);
 BT.begin(9600);
 pinMode (ENA, OUTPUT);
 pinMode (ENB, OUTPUT);
 pinMode (IN1, OUTPUT);
 pinMode (IN2, OUTPUT);
 pinMode (IN3, OUTPUT);
 pinMode (IN4, OUTPUT);  
}

void loop() {
  if(BT.available()){
  char dato=BT.read();

    switch(dato){
      case 'Arriba':
        Adelante();
        break;
      case 'Abajo':
        Atras();
        break;
      case 'Parar':
        Parar();
        break;
    }
  }
}
void Adelante (){
 //Dirección motor A
 digitalWrite (IN1, LOW);
 digitalWrite (IN2, HIGH);
 analogWrite (ENA, 255); //Velocidad motor A
 //Dirección motor B
 digitalWrite (IN3, HIGH);
 digitalWrite (IN4, LOW);
 analogWrite (ENB, 255); //Velocidad motor B
}

void Atras (){
 //Dirección motor A
 digitalWrite (IN1, HIGH);
 digitalWrite (IN2, LOW);
 analogWrite (ENA, 255); //Velocidad motor A
 //Dirección motor B
 digitalWrite (IN3, LOW);
 digitalWrite (IN4, HIGH);
 analogWrite (ENB, 255); //Velocidad motor B
}

void Parar (){
 //Dirección motor A
 digitalWrite (IN1, LOW);
 digitalWrite (IN2, LOW);
 analogWrite (ENA, 0); //Velocidad motor A
 //Dirección motor B
 digitalWrite (IN3, LOW);
 digitalWrite (IN4, LOW);
 analogWrite (ENB, 0); //Velocidad motor A
} 
{ 
  delay(200);
  int tiempo = sonar.ping_median();
  int distancia = tiempo / US_ROUNDTRIP_CM;
  // Imprimir el tiempo medido en la consola
  Serial.print("Tiempo: ");
  Serial.print(tiempo);
  Serial.println(" microsegundos");
  // Imprimir la distancia medida en la consola
  Serial.print("Distancia: ");
  // US_ROUNDTRIP_CM constante para determinar la distancia. Convertir el tiempo en distancia (0 = indica fuera de rango)
  Serial.print(distancia);
  Serial.println(" cm");
  /*  */
  if (distancia > 0){  // hay espacio
    if(distancia > 30){
      Adelante();
      if(distancia <= 20){
        delay(50);
        Parar();
      }
    }
  }
}

That's not going to work.

Oops

Extra }{ in function Parar() ends the function and orphans the rest of it's code.

Thanks, your idea have helped me a lot, I quit the }{ and it works perfectly

"Perfectly"?

Exactly what do you believe is wrong with that??

The largest a multicharacter constant can be is the same size as an "int", so two characters, assuming an AVR.
But the OP is only reading one character from BlueTooth

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.