const int analogPin = A0; //Pino conectado ao potenciômetro
const int ledCount = 9; // Número de Leds
int ledPins[] = {2,3,4,5,6,7,8,9,10}; // Pinos conectados aos LEDs
// Executar uma única vez no início do programa
void setup() {
// put your setup code here, to run once:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}
// Iniciar um loop
// Loop contínuo
void loop() {
// put your main code here, to run repeatedly:
int sensorReading = analogRead(analogPin); // Entrada analógica
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
if (thisLed < ledLevel) { // Acende os LEDs em sequência
digitalWrite(ledPins[thisLed], HIGH);
}
else { // Apagar os LEDs em sequência
digitalWrite(ledPins[thisLed], LOW);
}
}
}