const int ledCount = 10; // the number of LEDs in the bar graph
int ledPins[] = {
2, 3, 4, 5, 6, 7, 8, 9, 10, 11
}; // an array of pin numbers to which LEDs are attached
void setup() {
// put your setup code here, to run once:
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
// loop over the LED array:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
digitalWrite(ledPins[thisLed], HIGH);
delay(200);
}
for (int thisLed = ledCount; thisLed >= 0; thisLed--) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
digitalWrite(ledPins[thisLed], LOW);
delay(200);
}
delay(200);
}