Programming problem

hey!! I have this problem with my code: error: expected unqualified-id before ‘{’ token

I really hope you can help me. I’m so beginner wih this and I can’t found what I did wrong. Thank you so much people!

This is my code:

int trigPin = 12;
int echoPin = 11;
long timeperiod, cm;
const int analogOutPin = 9;
int brightness;

void setup()
{
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop(){

if (timeperiod > 50)
analogWrite(analogOutPin,0);
}{

if (timeperiod 10 < 50){
for(brightness = 0; brightness < 256; brightness++){
analogWrite(led,brightness);
delay(10);}
}}
if (timeperiod < 10)
analogWrite(analogOutPin,0);

{
digitalWrite(trigPin, LOW);
delayMicroseconds(20);
digitalWrite(trigPin, HIGH);
delayMicroseconds(0);
digitalWrite(trigPin, LOW);

timeperiod = pulseIn(echoPin, HIGH);

cm = microsecondsToCentimeters(timeperiod);
Serial.print(“dist=”);
Serial.print(cm);
Serial.println();

delay(10);
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 /2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29/ 2;
}

void loop(){
  
  if (timeperiod > 50)
  analogWrite(analogOutPin,0);
}

That’s the whole of your loop function, as.far as the compiler is concerned.

Use code-tags when posting code. Also press Ctrl-T in your arduino ide to auto format your code before posting.
The error message tells you, what is wrong, just look at this:

void loop() {
    // ...
}{

The loop function ends with the first '}'. Now what does the '{' right after that do?

Thank you so much for the answers.

I putted a lot of "{" because if not,, I have this problem: expected unqualified-id before 'if'

Use Ctrl-T in the IDE editor might be of help here...

Do you understand the purpose of the curly brackets? You should read up on that and not just put a lot of those in your code.

LightuC:
Do you understand the purpose of the curly brackets? You should read up on that and not just put a lot of those in your code.

Normally I understand their purpose but when I searched information for "the expected unqualified-id before 'if'" problem, I started to put curly brackets as the information that I found told me.

I'm sorry if I am bodering you but I really don't know what els do.

Thank you so much.

Check that every opening { has one and only one closing } and that these are around the instructions that should be grouped together. Using Ctrl-T should help you see these.

They mean something so if you just put them in randomly you confuse us, yourself and even more importantly the compiler.

Steve

Then you have to decide what you want

  if (timeperiod 10 < 50){

to do.