Arrays woot! Lauren's work of genius...

The lesson today is about arrays. An array is used when you want to light up lights in ports that are not sequentially numbered. The integers are declared in brackets and are identified as positions, starting with position 0.

int woot[] = {3,5,6,9,10,11}; //Declares PMW ports in an array

void setup() //no setup

{

}

void loop ()

{

for(int x = 0; x <= 5; x++) //for loop. "x" declares the position of the integers listed in the array (6 positions).

{

for(int value = 0; value <= 255; value+=5) //for loop. declares fade-in setting (0-255)

{

analogWrite(woot[x], value); //commands array to preform the value funtion declared in the last for loop.

delay(30); //wait 3 miliseconds(duh)

}

for (int value = 255; value>= 0; value-=5) //for loop.declares fade-out setting (0-255)

{

analogWrite(woot[x], value); //commands array to preform the value funtion declared in the last for loop.

delay(30); //same as before. It hasn't changed.

}

}

}

The first for loop identifies x being equal to the position numbers. The example above says x starts at position 0, and if x is less than or equal to position 5 (the last position shown above) than x increases by one position. This for loop is then followed by a for loop to fade lights in and fade lights out. For information about fading, see the lesson about analogWrite. Once the for loops for fading run through the first position, the loop starts over in the next position. The points listed in int woot[] are pmw ports that allow for fading. When writing additional for loops in the array (like the fading in this example) be sure to add x in the brackets for the int (int woot[x]).