// Arduino course
// Homework 3
// Write a program that turns ON and OFF the LEDs depending on the
// position of the potenciometer.
// One, and only one, LED should be ON at a time.
// Each LED must represent about 20% of the range.
int led_pins[] = {8,9,10,11,12};
int number_led = 5;
int potenc = A5;
void setup() {
for(int x=0; x < number_led; x++) {
pinMode(led_pins[x], OUTPUT);
}
pinMode(potenc , INPUT);
}
void loop() {
int potenc_value = analogRead(potenc);
int led_index = map(potenc_value, 0, 1023, 0, number_led);
for(int y=0; y < number_led; y++) {
if (y == led_index) {
digitalWrite(led_pins[y], HIGH);
} else {
digitalWrite(led_pins[y], LOW);
}
}
}