Reputation: 9
Can someone explain me why are they using the same variable "i" to determine which pins are high. I understood everything except the function block at barGraphDisplay. Like how can you set one pin at high and all the rest at low with only "i" ? The way I see it, the function chooses only one position of the array and evaluates it.
Upvotes: 0
Views: 141
Reputation: 156
First, the variable i in barGraphDisplay is scoped to the function, so the variable i in loop() is not relevant.
Second, the call to digitalWrite is inside a for loop, so i isn't just one number, it's all values in ledCount. Additionally, it's inside an if / else block, so if i == ledOn
then the LED is set to HIGH, otherwise LOW. But the same pin (denoted by the value of i) is never set to both states.
Upvotes: 1