help with sketch , do not understand error message

help fix sketch - needs to repeat this Light pattern 3X then stop:
Turn LED on for one second, off for one second
Turn LED on for two seconds, off for one second
Turn LED on for three seconds, off for one second
Turn LED on for four seconds, off for a second
Turn LED on for five seconds, off for a second
Delay five seconds

Arduino: 1.6.5 (Mac OS X), Board: "Arduino Uno"

sketch_sep12flashLight:18: error: expected unqualified-id before 'for'
sketch_sep12flashLight:18: error: 'i' does not name a type
sketch_sep12flashLight:18: error: 'i' does not name a type
expected unqualified-id before 'for'

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

Sketch:

void setup() {
// put your setup code here, to run once:
#define LED 13
int i(13);
pinMode(LED, OUTPUT);
digitalWrite(LED,LOW);
}

void loop(void) {

flashLight(1,1); //turn the LED on (HIGH is the voltage level) for one second, off for one second
flashLight(2,1); //turn the LED on for two seconds, off for one second
flashLight(3,1); //turn the LED on for three seconds, off for a second
flashLight(4,1); //turn the LED on for four seconds, off for a second
flashLight(5,1); //turn the LED on for five seconds, off for a second
delay(5000); //followed by a delay of five seconds
}
for(i=0;i<3; i++1){

}

void flashLight(int onTime, int offTime) {

digitalWrite(LED, HIGH); delay(1000onTime);
digitalWrite(LED, LOW); delay(1000
offTime);

}

sketch_sep12flashLight.ino (856 Bytes)

Welcome to the Forum. Please read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags ("</>") when posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.

like this

If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button.

Also, in this case, auto formatting your code might have helped you notice at least one of the problems with your program.

sketch_sep12flashLight:18: error: expected unqualified-id before 'for'

This means that something is wrong in line 18 just before the keyword 'for'. In your case it means that you can't put a 'for' loop outside of any function.

// It's a good idea to name pins using integer constants:
const int LED = 13;

void setup() {
  // put your setup code here, to run once:
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
}

void loop(void) {
  flashLight(1, 1); //turn the LED on (HIGH is the voltage level) for one second, off for one second
  flashLight(2, 1); //turn the LED on for two seconds, off for one second
  flashLight(3, 1); //turn the LED on for three seconds, off for a second
  flashLight(4, 1); //turn the LED on for four seconds, off for a second
  flashLight(5, 1); //turn the LED on for five seconds, off for a second
  delay(5000);      //followed by a delay of five seconds
}

// This code is outside the loop() function so it won't compile
//  for (i = 0; i < 3; i++1) {
//  
//  }

void flashLight(int onTime, int offTime) {
  digitalWrite(LED, HIGH);
  delay(1000 * onTime);   // Note that values of onTime above 32 will produce unexpected results
  digitalWrite(LED, LOW);
  delay(1000 * offTime);   // Note that values of offTime above 32 will produce unexpected results
}

Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read...

@aarg : Thanks a lot for this tip. Will definitely jot it somewhere for later use... :smiley:

Remove your attempt at a for loop and let the loop() function do what its name implies.

Or put the for loop inside of setup() and put all the loop() code in the for loop. That will run the way you say you want. 5 flashes of different durations, three times then off until reset. Fix the increment in the for loop (i++1 is nonsense). Loop() will be empty.

dsauriol:
@anon57585045 : Thanks a lot for this tip. Will definitely jot it somewhere for later use... :smiley:

No need to jot anything down. Everything I said is covered in the forum stickies.