Your problem is that you have code that is not inside a function.
Your posted this as your code to date:
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
for (int i = 0; i < 5; i++) {
digitalWrite(13, HIGH );
delay(100);
digitalWrite(13, LOW);
delay(100);
}
So as a quick tutorial, you MUST define two functions in the Arduino ‘system’. The first is setup and the second is loop. Without these two functions, the compiler is not going to be happy. Setup is called only one time each time the processor is powered up or reset. ‘loop’ is called as soon as the last call to loop completes. ‘loop’ is essensialy inside an infinite loop like this:
for(;;){
loop();
}
Now the code you have after the definition of setup (the loop of 5), is code that is not inside a function. C, unlike a language like Python, requires that all code exist inside a function. So if you only want to execute your loop 5 times ever (for each reset), then you might like something like this:
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
for (int i = 0; i < 5; i++) {
digitalWrite(13, HIGH );
delay(100);
digitalWrite(13, LOW);
delay(100);
}
}
void loop(void) {
delay(1000); // Do nothing over and over again
}
If you want to continue to send pulses you could do something like this:
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
void loop(void){
// Sent out five pulses on pin 13
for (int i = 0; i < 5; i++) {
digitalWrite(13, HIGH );
delay(100);
digitalWrite(13, LOW);
delay(100);
}
delay(1000); // Wait a second before doing it all again.
}
As for the speed, using digitalWrite is “very” slow. It has lots of work to do to figure out what port to use based on the pin number and the mask to use and other overheads. If you want to generate pulses as fast as possible, look into direct port manipulation. Google will be your friend.