How to use ARRAYS in your Arduino sketches

Today we will take a look at the basic use of arrays in an Arduino sketch.

 

check us out on Facebook: https://www.facebook.com/zarduino/

 

SCHEMATIC:

 

ARDUINO CODE:

int led[10] = {2, 3, 4, 5, 6, 8, 9, 10, 11, 12};
int del;
void setup()
{
for (int i; i <= 9; i++)
{
pinMode(led[i], OUTPUT);
}
}
void loop() {
del = analogRead (A1);
del = map(del, 0, 1023, 10, 100);
for (int i = 0; i <= 9; i++)
{
digitalWrite(led[i], HIGH);
delay(del);
}
delay(del * 4);
for (int i = 9; i >= 0; i–)
{
digitalWrite(led[i], LOW);
delay(del);
}
delay(del * 4);
}