//Canales a Leer
#define L 7
//PINS Izquierdos
#define L1 10
#define L2 9
#define L3 6
//Umbrales para cada PIN
#define UMBRAL1 15
#define UMBRAL2 30
#define UMBRAL3 45
#define UMBRAL4 55
#define UMBRAL5 70
#define UMBRAL6 85
#define UMBRAL7 100
//Variables donde guardamos
//El valor de R y L
int l;
void setup() {
//Ponemos todos pins del 0 a 6
//en modo OUTPUT
for (int i = 0; i < 10; i++)
pinMode(i, OUTPUT);
}
void loop() {
//Leemos los canales
l = analogRead(L);
//Encemos los leds que correspondan
if (l > UMBRAL1)
digitalWrite(L2, HIGH);
else
digitalWrite(L2, LOW);
if (l > UMBRAL2)
digitalWrite(L1, HIGH);
else
digitalWrite(L1, LOW);
if (l > UMBRAL3)
digitalWrite(L3, HIGH);
else
digitalWrite(L3, LOW);
if (l > UMBRAL4)
digitalWrite(L1, HIGH);
digitalWrite(L2, HIGH);
else
digitalWrite(L1, LOW);
digitalWrite(L2, LOW);
if (l > UMBRAL5)
digitalWrite(L3, HIGH);
digitalWrite(L2, HIGH);
else
digitalWrite(L3, LOW);
digitalWrite(L2, LOW);
if (l > UMBRAL6)
digitalWrite(L1, HIGH);
digitalWrite(L3, HIGH);
else
digitalWrite(L1, LOW);
digitalWrite(L3, LOW);
if (l > UMBRAL7)
digitalWrite(L1, HIGH);
digitalWrite(L2, HIGH);
digitalWrite(L3, HIGH);
else
digitalWrite(L1, LOW);
digitalWrite(L2, LOW);
digitalWrite(L3, LOW);
}
tengo ese codigo, pero me da este error:
sketch_apr30b.ino: In function 'void loop()':
sketch_apr30b.ino:56:2: error: 'else' without a previous 'if'
sketch_apr30b.ino:63:2: error: 'else' without a previous 'if'
sketch_apr30b.ino:70:2: error: 'else' without a previous 'if'
sketch_apr30b.ino:78:2: error: 'else' without a previous 'if'
Error de compilación
otra duda qye tengo, se me suman los LED, y lo que kiero es que cada vez que se pase de un "umbral" a otro, se encienda el LED que sale, no el LED correspondiente y todos los anteriores