~ubuntu-branches/debian/experimental/arduino/experimental

« back to all changes in this revision

Viewing changes to build/shared/examples/5.Control/ForLoopIteration/ForLoopIteration.pde

  • Committer: Package Import Robot
  • Author(s): Scott Howard
  • Date: 2012-03-11 18:19:42 UTC
  • mfrom: (1.1.5) (5.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20120311181942-be2clnbz1gcehixb
Tags: 1:1.0.1~rc1+dfsg-1
New upstream release, experimental.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  For Loop Iteration
3
 
 
4
 
 Demonstrates the use of a for() loop. 
5
 
 Lights multiple LEDs in sequence, then in reverse.
6
 
 
7
 
 The circuit:
8
 
 * LEDs from pins 2 through 7 to ground
9
 
 
10
 
 created 2006
11
 
 by David A. Mellis
12
 
 modified 5 Jul 2009
13
 
 by Tom Igoe 
14
 
 
15
 
This example code is in the public domain.
16
 
 
17
 
 http://www.arduino.cc/en/Tutorial/ForLoop
18
 
 */
19
 
 
20
 
int timer = 100;           // The higher the number, the slower the timing.
21
 
 
22
 
void setup() {
23
 
  // use a for loop to initialize each pin as an output:
24
 
  for (int thisPin = 2; thisPin < 8; thisPin++)  {
25
 
    pinMode(thisPin, OUTPUT);      
26
 
  }
27
 
}
28
 
 
29
 
void loop() {
30
 
  // loop from the lowest pin to the highest:
31
 
  for (int thisPin = 2; thisPin < 8; thisPin++) { 
32
 
    // turn the pin on:
33
 
    digitalWrite(thisPin, HIGH);   
34
 
    delay(timer);                  
35
 
    // turn the pin off:
36
 
    digitalWrite(thisPin, LOW);    
37
 
  }
38
 
 
39
 
  // loop from the highest pin to the lowest:
40
 
  for (int thisPin = 7; thisPin >= 2; thisPin--) { 
41
 
    // turn the pin on:
42
 
    digitalWrite(thisPin, HIGH);
43
 
    delay(timer);
44
 
    // turn the pin off:
45
 
    digitalWrite(thisPin, LOW);
46
 
  }
47
 
}