/*A sketch to demonstrate array declaration,
initialization and referencing elements in an array.
In other words - lots of basic and practical array stuff.
*/
//Declare an initialize an array to hold pin numbers.
byte LEDpinArray[4] = { 6, 8, 10, 12};
/*Alternately we could have written:
byte LEDpinArray[] = { 6, 8, 10, 12}; //this is equivalent
We might also use a variable to define the size of our array
const byte LEDpinArraySize = 4;
byte LEDpinArray[LEDpinArraySize] = { 6, 8, 10, 12};
The only caveat, is that the variable MUST be a constant.
*/
//Set some delay times to for blinking the LEDs
const int longerDelayTime_ms = 1000;
const int shorterDelayTime_ms = 300;
void setup() {
//Set the modes of the pins in the pin as array outputs
pinMode(LEDpinArray[0], OUTPUT);
pinMode(LEDpinArray[1], OUTPUT);
pinMode(LEDpinArray[2], OUTPUT);
pinMode(LEDpinArray[3], OUTPUT);
}//close setup
void loop() {
//Turn on All the LEDs
digitalWrite(LEDpinArray[0], HIGH);
digitalWrite(LEDpinArray[1], HIGH);
digitalWrite(LEDpinArray[2], HIGH);
digitalWrite(LEDpinArray[3], HIGH);
//Delay for a momment to see the LED stay lit
delay(longerDelayTime_ms);
//Turn off all the LEDs, but delay
digitalWrite(LEDpinArray[0], LOW);
delay(shorterDelayTime_ms);
digitalWrite(LEDpinArray[1], LOW);
delay(shorterDelayTime_ms);
digitalWrite(LEDpinArray[2], LOW);
delay(shorterDelayTime_ms);
digitalWrite(LEDpinArray[3], LOW);
delay(shorterDelayTime_ms);
}//close loop