const int ledCount = 10; // amount of pins we will use. This integer will remain constant
int ledPins[] = {3,4,5,6,7,8,9,10,11,12}; // array of pins
void setup() {
// setup the program
for(int i = 0; i < 10; i++){ // go through array and set all the pins to output
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
for(int i = 0; i < ledCount; i++){
barGraphDisplay(i); // the ith LED of the bar graph will light up
}
}
// determine which LED will light up
void barGraphDisplay(int ledOn){
for(int i = 0; i < ledCount; i++){
if(i == ledOn){
digitalWrite(ledPins[i], HIGH); // selected pin output HIGH
} else {
digitalWrite(ledPins[i], LOW); // other pins output LOW
}
}
delay(100); // delay 100 ms
}