const int POT_PIN = 34;
const int leds[] = {13, 12, 14, 27, 26, 25, 33, 32};
void setup() {
Serial.begin(9600);
analogReadResolution(12);
// Configura todos los LEDs como salidas
for(int i = 0; i < 8; i++) {
pinMode(leds[i], OUTPUT);
}
}
void loop() {
int potValue = analogRead(POT_PIN);
float voltage = (potValue / 4095.0) * 3.3;
Serial.print("El voltaje: ");
Serial.print(voltage);
Serial.print("V y ADC: ");
Serial.println(potValue);
int numLeds = map(potValue, 0, 4095, 0, 8);
on_leds(numLeds);
delay(100);
}
void on_leds(int num) {
off_leds();
for (int i = 0; i < num; i++) {
digitalWrite(leds[i], HIGH);
}
}
void off_leds() {
for (int i = 0; i < 8; i++) {
digitalWrite(leds[i], LOW);
}
}