Expected unqualified-id before "for" Arduino

1

This script gives me an error called expected unqualified-id before "for". This is the script:

const int LED=9;
int i=0;

void setup() {
  pinMode(LED,OUTPUT);
}

void loop() {
  for(i=0;i<255;i++)
    analogWrite(LED,i);
    delay(10);
  }

  for (i = 255; i > 0; i--) {
    analogWrite(LED,i);
    delay(10);
  }
}
    
asked by JuanVan12 29.09.2016 в 15:04
source

1 answer

1

In your code I see two problems:

  • The first for has no opening key. If you compile it is because you forgot to indicate it when copying the code.

  • The first for iterates in the range [0-254] while the second one does it in the range [255-1]. It gives the impression that the second rank is not correct.

If this is the error, the solution would be:

for (i = 254; i >= 0; i--) {
  analogWrite(LED,i);
  delay(10);
}

Greetings

    
answered by 29.09.2016 / 15:09
source