const int nrLeds = 5;
const int ledPins[] = { 2, 3, 4, 5,6};
const int analogInPin = 0;
const int wait = 30;
const boolean LED_ON = HIGH;
const boolean LED_OFF = LOW;
int sensorValue = 0;
int ledLevel = 0;
void setup() {
for (int led = 0; led < nrLeds; led++)
{
pinMode(ledPins[led], OUTPUT);
}
}
void loop() {
sensorValue = analogRead(analogInPin);
ledLevel = map(sensorValue, 0, 1023, 0, nrLeds);
for (int led = 0; led < nrLeds; led++)
{
if (led < ledLevel ) {
digitalWrite(ledPins[led], LED_ON);
}
else {
digitalWrite(ledPins[led], LED_OFF);
}
}
}