Está en la página 1de 2

Programa Encendido 3 leds con potenciómetro

int i = 0;

int Potenpin = A1;

int valorPoten = 0;

int pinLedV = 12;

int pinLedA = 8;

int pinLedR = 3;

void setup()

pinMode(Potenpin, INPUT);

pinMode(pinLedV, OUTPUT);

pinMode(pinLedA, OUTPUT);

pinMode(pinLedR, OUTPUT);

Serial.begin(9600);

void loop()

valorPoten = analogRead(Potenpin);

Serial.println(valorPoten, DEC);

delay(100);

//preguntamos y en función del valor del potenciómetro encendemos el pin correspondiente

if (valorPoten >= 10 && valorPoten < 200) digitalWrite(pinLedV, HIGH);


if (valorPoten >= 400 && valorPoten < 600) digitalWrite(pinLedA, HIGH);

if (valorPoten >= 800 && valorPoten < 900) digitalWrite(pinLedR, HIGH);

if (valorPoten >= 900) digitalWrite(pinLedR, HIGH);

//si el valor es menor de diez, ordenamos apagar todos los leds con una función que llamaremos
apagarLeds()

if (valorPoten < 10 ) apagarLeds();

//la siguiente función tiene una estructura de control for o bucle que ejecutará 6 veces la
instrucción de apagar el led correspondiente

//se sabe el led que tiene que apagar por la variable “i” que tendrá valores desde el inicial 8 hasta
el final 13

void apagarLeds()

for (i = 8; i < 14; i++)

digitalWrite(i, LOW);

También podría gustarte