aboutsummaryrefslogtreecommitdiff
path: root/Arduino_STM32-MIDI/examples/Control/ForLoopIteration/ForLoopIteration.ino
blob: f65706ba14aac5b006fb6b56a47c00039126abb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
  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, through resistors

  created 2006
  by David A. Mellis
  modified 5 Jul 2009
  by Tom Igoe

  http://leaflabs.com/docs/lang/cpp/for.html

  Modified for Maple
  by LeafLabs
*/

int delayTime = 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 <= 7; thisPin++) {
        pinMode(thisPin, OUTPUT);
    }
}

void loop() {
    // Loop from the lowest pin to the highest:
    for (int thisPin = 2; thisPin <= 7; thisPin++) {
        // Turn the pin on:
        digitalWrite(thisPin, HIGH);
        delay(delayTime);
        // 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(delayTime);
        // Turn the pin off:
        digitalWrite(thisPin, LOW);
    }
}