Tutorial.ForLoop History

Show minor edits - Show changes to markup

May 02, 2012, at 04:07 PM by Scott Fitzgerald -
Changed line 41 from:
to:
November 16, 2011, at 04:17 AM by Scott Fitzgerald -
Changed line 41 from:
to:
September 30, 2011, at 03:18 AM by Scott Fitzgerald -
Changed line 41 from:
to:
September 28, 2010, at 01:30 PM by Tom Igoe -
Deleted lines 34-35:
Added lines 39-40:
September 24, 2010, at 05:59 AM by Tom Igoe -
Changed lines 31-32 from:
to:
September 23, 2010, at 10:39 PM by Christian Cerrito -
Changed lines 3-5 from:

For Loop

(aka Knight Rider)

to:

For Loop (aka The Knight Rider)

September 23, 2010, at 10:39 PM by Christian Cerrito -
Changed line 3 from:

For Loop

to:

For Loop

September 18, 2010, at 12:11 AM by Christian Cerrito -
Changed lines 46-47 from:
to:

See Also:

September 18, 2010, at 12:10 AM by Christian Cerrito -
Changed lines 6-7 from:

Often you want to iterate over a series of pins and do something to each one. For instance, this example blinks 6 LEDs attached the Arduino by using a for() loop to cycle back and forth through digital pins 2-7. The LEDS are turned on and off, in sequence, by using both the digitalWrite() and delay() functions .

to:

Often you want to iterate over a series of pins and do something to each one. For instance, this example blinks 6 LEDs attached the Arduino by using a for() loop to cycle back and forth through digital pins 2-7. The LEDS are turned on and off, in sequence, by using both the digitalWrite() and delay() functions .

September 17, 2010, at 10:44 PM by Tom Igoe -
Changed lines 44-46 from:

(:divend:

to:
September 16, 2010, at 10:16 PM by Tom Igoe -
Changed line 42 from:
to:
September 16, 2010, at 08:05 AM by Christian Cerrito -
Changed lines 6-7 from:

Often you want to iterate over a series of pins and do something to each one. For instance, this example blinks 6 LEDs attached the Arduino by using a for() loop to cycle back and forth through digital pins 2-7. The LEDS are turned on and off, in sequence, by using both the digitalWrite() and delay() functions .

to:

Often you want to iterate over a series of pins and do something to each one. For instance, this example blinks 6 LEDs attached the Arduino by using a for() loop to cycle back and forth through digital pins 2-7. The LEDS are turned on and off, in sequence, by using both the digitalWrite() and delay() functions .

September 16, 2010, at 07:59 AM by Christian Cerrito -
Changed lines 40-41 from:

In the main loop of the code, two for() loops are used to loop incrementally, turning on the LEDs, one by one, connected to lowest pin to the highest.

to:

In the main loop of the code, two for() loops are used to loop incrementally, stepping through the LEDs, one by one, from pin 2 to pin seven. Once pin 7 is lit, the process reverses, stepping back down through each LED.

September 16, 2010, at 07:56 AM by Christian Cerrito -
September 16, 2010, at 07:53 AM by Christian Cerrito -
Changed lines 6-7 from:

Often you want to iterate over a series of pins and do something to each one. For instance, this example blinks 6 LEDs attached the Arduino by using a for() loop to cycle back and forth through digital pins 2-7. The LEDS are turned on and off, in sequence, by using both the [Reference/digitalWrite | digitalWrite()]] and delay() functions .

to:

Often you want to iterate over a series of pins and do something to each one. For instance, this example blinks 6 LEDs attached the Arduino by using a for() loop to cycle back and forth through digital pins 2-7. The LEDS are turned on and off, in sequence, by using both the digitalWrite() and delay() functions .

September 16, 2010, at 07:52 AM by Christian Cerrito -
Changed lines 6-7 from:

Often you want to iterate over a series of pins and do something to each one. For instance, this example blinks 6 LEDs, one by one, attached the Arduino by using a for() loop to cycle back and forth through digital pins 2-7.

to:

Often you want to iterate over a series of pins and do something to each one. For instance, this example blinks 6 LEDs attached the Arduino by using a for() loop to cycle back and forth through digital pins 2-7. The LEDS are turned on and off, in sequence, by using both the [Reference/digitalWrite | digitalWrite()]] and delay() functions .

Deleted lines 9-10:

This example makes use of 6 LEDs connected to the pins 2 - 7 on the board using 220 Ohm resistors. The sketch makes the LEDs blink in a sequence, one by one using only digitalWrite() and delay() .

September 16, 2010, at 07:50 AM by Christian Cerrito -
Changed lines 10-11 from:

This example makes use of 6 LEDs connected to the pins 2 - 7 on the board using 220 Ohm resistors. The sketch makes the LEDs blink in a sequence, one by one using only * digitalWrite() and * delay() .

to:

This example makes use of 6 LEDs connected to the pins 2 - 7 on the board using 220 Ohm resistors. The sketch makes the LEDs blink in a sequence, one by one using only digitalWrite() and delay() .

September 16, 2010, at 07:49 AM by Christian Cerrito -
Changed lines 10-11 from:

This example makes use of 6 LEDs connected to the pins 2 - 7 on the board using 220 Ohm resistors. The sketch makes the LEDs blink in a sequence, one by one using only digitalWrite(pinNumber,HIGH/LOW) and delay(time).

to:

This example makes use of 6 LEDs connected to the pins 2 - 7 on the board using 220 Ohm resistors. The sketch makes the LEDs blink in a sequence, one by one using only * digitalWrite() and * delay() .

September 16, 2010, at 07:48 AM by Christian Cerrito -
Changed lines 6-7 from:

Often you want to iterate over a series of pins and do something to each one. For instance, this example lights 6 LEDs attached the Arduino by using a for() loop to cycle back and forth through digital pins 2-7.

to:

Often you want to iterate over a series of pins and do something to each one. For instance, this example blinks 6 LEDs, one by one, attached the Arduino by using a for() loop to cycle back and forth through digital pins 2-7.

September 16, 2010, at 07:47 AM by Christian Cerrito -
Changed lines 6-7 from:

Often you want to iterate over a series of pins and do something to each one. For example, this example lights up a series of LEDs attached to pins 2 through 7 of the Arduino.

to:

Often you want to iterate over a series of pins and do something to each one. For instance, this example lights 6 LEDs attached the Arduino by using a for() loop to cycle back and forth through digital pins 2-7.

September 16, 2010, at 07:43 AM by Christian Cerrito -
Changed lines 49-51 from:
to:
Changed lines 51-54 from:
to:
September 16, 2010, at 07:41 AM by Christian Cerrito -
Changed lines 56-58 from:
  • Forloop? - Control multiple LEDs with a For Loop.
  • Whileloop? - Use a While Loop to calibrate a sensor while a button is being pressed.
  • Switchcase? - Choose between a number of discrete values in a manner that is the equivalent of using multiples If statements. This example shows how to divide a sensor's range into a set of four bands and to take four different actions depending on which band the result is in.
to:
  • ForLoop - Control multiple LEDs with a For Loop.
  • WhileLoop - Use a While Loop to calibrate a sensor while a button is being pressed.
  • SwitchCase - Choose between a number of discrete values in a manner that is the equivalent of using multiples If statements. This example shows how to divide a sensor's range into a set of four bands and to take four different actions depending on which band the result is in.
September 16, 2010, at 07:40 AM by Christian Cerrito -
Changed lines 56-58 from:
  • For Loop? - Control multiple LEDs with a For Loop.
  • While Loop? - Use a While Loop to calibrate a sensor while a button is being pressed.
  • Switch Case? - Choose between a number of discrete values in a manner that is the equivalent of using multiples If statements. This example shows how to divide a sensor's range into a set of four bands and to take four different actions depending on which band the result is in.
to:
  • Forloop? - Control multiple LEDs with a For Loop.
  • Whileloop? - Use a While Loop to calibrate a sensor while a button is being pressed.
  • Switchcase? - Choose between a number of discrete values in a manner that is the equivalent of using multiples If statements. This example shows how to divide a sensor's range into a set of four bands and to take four different actions depending on which band the result is in.
September 16, 2010, at 07:38 AM by Christian Cerrito -
September 16, 2010, at 07:38 AM by Christian Cerrito -
September 16, 2010, at 07:37 AM by Christian Cerrito -
Added lines 21-22:

Connect six LEDS, with 220 ohm resistors in series, to digital pins 2-7 on your Arduino.

Changed lines 39-40 from:
to:
September 16, 2010, at 07:28 AM by Christian Cerrito -
Added lines 12-18:

Hardware Required

  • Arduino Board
  • (6) 220 ohm resistors
  • (6) LEDs
  • hook-up wire
  • breadboard
Changed lines 40-53 from:
to:

(:divend:

  • if()
  • if...else
  • analogRead()
  • digitalWrite()
  • serial.begin()
  • serial.print()

  • For Loop? - Control multiple LEDs with a For Loop.
  • While Loop? - Use a While Loop to calibrate a sensor while a button is being pressed.
  • Switch Case? - Choose between a number of discrete values in a manner that is the equivalent of using multiples If statements. This example shows how to divide a sensor's range into a set of four bands and to take four different actions depending on which band the result is in.
  • Array: a variation on the For Loop example that demonstrates how to use an array.
September 16, 2010, at 07:24 AM by Christian Cerrito -
Changed lines 25-26 from:
to:
September 15, 2010, at 11:28 PM by Christian Cerrito -
Changed line 31 from:
to:
February 24, 2010, at 04:06 AM by Tom Igoe -
Changed lines 31-46 from:
 /*
   For Loop Iteration
  
  Demonstrates the use of a for() loop. 
  Lights multiple LEDs in sequence, then in reverse.
  
  The circuit:
  * LEDs from pins 2 through 7 to ground
  
  created 2006
  by David A. Mellis
  modified 5 Jul 2009
  by Tom Igoe 
  
  http://www.arduino.cc/en/Tutorial/ForLoop
  */
to:
Deleted lines 32-60:
 int timer = 100;           // The higher the number, the slower the timing.

 void setup() {
   // use a for loop to initialize each pin as an output:
   for (int thisPin = 2; thisPin < 8; thisPin++)  {
     pinMode(thisPin, OUTPUT);      
   }
 }

 void loop() {
   // loop from the lowest pin to the highest:
   for (int thisPin = 2; thisPin < 8; thisPin++) { 
     // turn the pin on:
     digitalWrite(thisPin, HIGH);   
     delay(timer);                  
     // turn the pin off:
     digitalWrite(thisPin, LOW);    
   }

   // loop from the highest pin to the lowest:
   for (int thisPin = 7; thisPin >= 2; thisPin--) { 
     // turn the pin on:
     digitalWrite(thisPin, HIGH);
     delay(timer);
     // turn the pin off:
     digitalWrite(thisPin, LOW);
   }
 }
September 26, 2009, at 06:43 PM by David A. Mellis -
Changed line 59 from:
   for (int thisPin = 0; thisPin < 8; thisPin++) { 
to:
   for (int thisPin = 2; thisPin < 8; thisPin++) { 
August 27, 2009, at 08:47 PM by Tom Igoe -
Added lines 18-20:

image developed using Fritzing. For more circuit examples, see the Fritzing project page

July 06, 2009, at 08:12 PM by Tom Igoe -
Changed line 3 from:

For Loop and Arrays

to:

For Loop

July 06, 2009, at 08:11 PM by Tom Igoe -
Added line 25:
Changed line 56 from:
   for (int thisPin = 0; i < 8; thisPin++) { 
to:
   for (int thisPin = 0; thisPin < 8; thisPin++) { 
Changed line 65 from:
   for (thisPin = 7; thisPin >= 2; thisPin--) { 
to:
   for (int thisPin = 7; thisPin >= 2; thisPin--) { 
Changed line 74 from:
to:
July 05, 2009, at 08:54 PM by Tom Igoe -
Added lines 1-73:

Share