const int pin = A0;
const int ledCount = 5;
int leds[] = {
0, 1, 2, 3, 4
};
void setup() {
// put your setup code here, to run once:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(leds[thisLed], OUTPUT);
}
}
void loop() {
// put your main code here, to run repeatedly:
int sensorReading = analogRead(pin);
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
if (thisLed < ledLevel) {
digitalWrite(leds[thisLed], HIGH);
}
else {
digitalWrite(leds[thisLed], LOW);
}
}
}