I have been having issues with a much larger project that I've been trying to diagnose with strange outputs. I finally have narrowed it down and I have realized that my Arduino is not recognizing "for loops." It just skips right through them and performs no action. So, to test my theory, I got rid of the entire program, and made this simple sketch....
int x;
void setup()
{
Serial.begin(9600);
}
void loop()
{
for (x=0; x > 5000; x++)
{
Serial.println(x);
delay(200);
}
}
The output of this sketch is absolutely nothing. It skips over the for loop and does nothing. So, I added a little line at the end of the sketch just to make sure there is serial communications.
Serial.Println("testing");
That is the last line before the end of the loop. The output is a continuous stream of "testing" but it completely has skipped over the for loop. I then thought I'd outsmart the software and do what I want to do inside of a do/while loop.
That makes no sense. It should stay in the do/while loop until it reaches 5000. I have other parts of my program that use the do/while loop and they work normally. Am I doing something wrong here? This a very simple task and I'm even embarrassed to post this here because it is a very basic programming concept. By the way, I have now tried this on two separate MEGA boards with the exact same results. I upgraded my software tot he 1.0.2 with the same results. I cannot complete my project without some sort of a loop, and this makes no sense to me. Any insight would be much appreciated.
I see my mistake in the for loop now. Thanks for pointing that out. I'm embarrassed that I have made such a simple mistake. Stupid stupid stupid. Excuse my retardation.
But did you change the direction of the < vs > in the for?- remember that the block is only executed while the condition is true, so when you make it 0, and test to see if it's >5000, that's false so it leaps out straightaway.
Edit... we posted at the same time. Glad to help. The simplest mistakes are the hardest to spot!
No kidding... I'm embarrassed that I was stumped by such a simple thing. I was thinking backwards the whole time and no matter how many times I looked at it, I kept telling myself... "Nope, that's right." such a simple deal... ugh...