Thanks for including your complete code. Please also put it inside "code" tags. It's the hash-mark (#) symbol in the editor.
int outPin = 8; // digital pin 8
void setup()
{
pinMode(outPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
for (int outPin=0; outPin <= 20; outPin++)
noInterrupts(); // turn interrupt off for timing accuracy
digitalWrite(outPin, HIGH); // sets the pin on
delayMicroseconds(7); // pauses for 7 (actual ontime 10us seen on scope) microseconds
digitalWrite(outPin, LOW); // sets the pin off
delayMicroseconds(10); // pauses for 10 (actual offtime 15us seen on scope) microseconds
}
Your use of the for() loop is incorrect. What you are doing is declaring a new variable "outPin" in the scope of the for() loop, which starts at the value 0 and increments by one each iteration of the loop until it reaches 20. Then you are writing to outPin. You have declared two copies of a variable named outPin--one in the global scope, which has value 8, and one in the scope of the for() loop, which goes from 0 to 20. This is known as variable overloading, and there are some cases when it can be a good thing, but mostly, it is a bad idea, and is confusing, and it is probably not what you meant to do.
Just to expound a bit more... what your loop is doing is this:
Write HIGH to pin 1 for 10 us.
Write LOW to pin 1 for 15 us.
Write HIGH to pin 2 for 10 us.
Write LOW to pin 2 for 15 uS
... pin 3
... pin 4
... pin 5
etc...
... pin 20
What you want is something like this:
for(int x = 0; x < 20; x++)
{
digitalWrite(outPin, HIGH)
... etc...
}
In other words, use x as a temporary counter variable within the scope of the for() loop and leave outPin alone.
Another note: it would probably be better to call noInterrupts() just before the for() loop, rather than calling it multiple times from within the loop. Also, don't forget that you must re-enable interrupts using interrupts() as soon as possible, or things will get screwy. So I would suggest:
noInterrupts();
for(x = 0; x < 20; x++)
{
// digitalWrites go here
}
interrupts();