Tuesday, May 25, 2010

Some for-loop examples

//(1) Print 0 1 2 ...9 to serial screen
for(int i = 0; i <10; i =" 100;" i =" 0;" i =" 0;" style="font-weight:bold;">i=i+2) {
Serial.println(i);
}

//(5) Print 0 1 2 ...999. You don't have to use i as a variable.
for(int longUselessVariable = 0; longUselessVariable <10000 ;longUselessVariable++ ) {
Serial.println(longUselessVariable );
}

//(6) The for loop can repeat any code between the { and the }
//Output 10 blinks then go to the next piece of code
for(int i = 0; i <10 ;i++) {
digitalWrite(ledPin, HIGH); // set the LED on
delay(100); // wait for a second
digitalWrite(ledPin, LOW); // set the LED off
delay(1000); // wait for a second
}
//next piece of code goes here

No comments:

Post a Comment