source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/05.Control/Arrays/Arrays.ino @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

File size: 1.5 KB
Line 
1/*
2  Arrays
3
4 Demonstrates the use of  an array to hold pin numbers
5 in order to iterate over the pins in a sequence.
6 Lights multiple LEDs in sequence, then in reverse.
7
8 Unlike the For Loop tutorial, where the pins have to be
9 contiguous, here the pins can be in any random order.
10
11 The circuit:
12 * LEDs from pins 2 through 7 to ground
13
14 created 2006
15 by David A. Mellis
16 modified 30 Aug 2011
17 by Tom Igoe
18
19This example code is in the public domain.
20
21 http://www.arduino.cc/en/Tutorial/Array
22 */
23
24int timer = 100;           // The higher the number, the slower the timing.
25int ledPins[] = {
26  2, 7, 4, 6, 5, 3
27};       // an array of pin numbers to which LEDs are attached
28int pinCount = 6;           // the number of pins (i.e. the length of the array)
29
30void setup() {
31  // the array elements are numbered from 0 to (pinCount - 1).
32  // use a for loop to initialize each pin as an output:
33  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
34    pinMode(ledPins[thisPin], OUTPUT);
35  }
36}
37
38void loop() {
39  // loop from the lowest pin to the highest:
40  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
41    // turn the pin on:
42    digitalWrite(ledPins[thisPin], HIGH);
43    delay(timer);
44    // turn the pin off:
45    digitalWrite(ledPins[thisPin], LOW);
46
47  }
48
49  // loop from the highest pin to the lowest:
50  for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
51    // turn the pin on:
52    digitalWrite(ledPins[thisPin], HIGH);
53    delay(timer);
54    // turn the pin off:
55    digitalWrite(ledPins[thisPin], LOW);
56  }
57}
Note: See TracBrowser for help on using the repository browser.