#define POT1 A0
#define POT2 A1
#define TOTLED 8 // Total LEDs
/********** Objetos **********/
// ninguno
/********** Variables **********/
int led[TOTLED] = {
2, 3, 4, 5, 6, 7, 8, 9};
/********** Configuracion **********/
void setup() {
int pos=0;
while (pos < TOTLED){
pinMode(led[pos], OUTPUT);
pos=pos+1;
}
pinMode(POT1, INPUT);
pinMode(POT2, INPUT);
} // end setup()
/********** Ciclo Principal **********/
void loop() {
// Sensores
int t_encendido = analogRead(POT1);
int t_apagado = analogRead(POT2);
// Acciones
for (int pos = 0; pos < TOTLED; pos++) {
on(led[pos], t_encendido);
off(led[pos], t_apagado);
}
for (int pos = TOTLED-2; pos > 0; pos--) {
on(led[pos], t_encendido);
off(led[pos], t_apagado);
}
} // end loop()
/********** Funciones **********/
// Pone en +5V el pin indicado, durante tantos milisegundos
void on(int pin, int ms){
digitalWrite(pin, HIGH);
delay(ms);
} // end on()
// Pone en GND el pin indicado, durante tantos milisegundos
void off(int pin, int ms){
digitalWrite(pin, LOW);
delay(ms);
} // end off()
/********** Fin ***********/