/*
Arrays
Demonstrates the use of an array to hold pin numbers in order to iterate over
the pins in a sequence. Lights multiple LEDs in sequence, then in reverse.
Unlike the For Loop tutorial, where the pins have to be contiguous, here the
pins can be in any random order.
The circuit:
- LEDs from pins 2 through 7 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Arrays
*/inttimer=100;// The higher the number, the slower the timing.
intledPins[]={2,7,4,6,5,3};// an array of pin numbers to which LEDs are attached
intpinCount=6;// the number of pins (i.e. the length of the array)
33
34
35
36
37
// first visible ASCIIcharacter '!' is number 33:
intthisByte=33;// you can also write ASCII characters in single quotes.
// for example, '!' is the same as 33, so you could also use this:
// int thisByte = '!';
voidsetup(){// the array elements are numbered from 0 to (pinCount - 1).
// use a for loop to initialize each pin as an output:
for(intthisPin=0;thisPin<pinCount;thisPin++){pinMode(ledPins[thisPin],OUTPUT);}}
voidloop(){// loop from the lowest pin to the highest:
for(intthisPin=0;thisPin<pinCount;thisPin++){// turn the pin on:
digitalWrite(ledPins[thisPin],HIGH);delay(timer);// turn the pin off:
digitalWrite(ledPins[thisPin],LOW);}// loop from the highest pin to the lowest:
for(intthisPin=pinCount-1;thisPin>=0;thisPin--){// turn the pin on:
digitalWrite(ledPins[thisPin],HIGH);delay(timer);// turn the pin off:
digitalWrite(ledPins[thisPin],LOW);}}