Paso 3: El código
#define trigPin 3 //Sonar Trigueros#define echoPinL 4 //Left eco de sonar
#define echoPinF 5 //Front eco de sonar
#define echoPinR 6 //Right eco de sonar
#define echoPinB 7 //Back eco de sonar
#define vibrar 10 //Vibrate + Led pin
#define disSelect A3 //Distance Selector analógico pin
int durationL, durationF, durationR, durationB, distanceL, distanceF, distanceR, distanceB, dSelValue;
void setup() {}
Serial.Begin (9600);
pinMode (trigPin, salida);
pinMode (echoPinL, entrada);
pinMode (echoPinF, entrada);
pinMode (echoPinR, entrada);
pinMode (echoPinB, entrada);
pinMode (vibrar, salida);
pinMode (disSelect, entrada);
pinMode (13, salida);
digitalWrite (13, bajo);
}
void loop() {}
dSelValue = mapa (analogRead (disSelect), 0,1023,20, 400);
Serial.Print ("distancia seleccione:");
Serial.println (dSelValue);
Triger();
durationL = pulseIn (echoPinL, HIGH);
distanceL = /29.1 (durationL/2);
Serial.Print ("izquierda =");
Serial.println (distanceL);
Serial.Print ("Triger =");
Serial.println (digitalRead (trigPin));
Delay (200);
Triger();
durationF = pulseIn (echoPinF, HIGH);
distanceF = /29.1 (durationF/2);
Serial.Print ("frontal =");
Serial.println (distanceF);
Serial.Print ("Triger =");
Serial.println (digitalRead (trigPin));
Delay (200);
Triger();
durationR = pulseIn (echoPinR, HIGH);
distanceR = /29.1 (durationR/2);
Serial.Print ("derecha =");
Serial.println (distanceR);
Serial.Print ("Triger =");
Serial.println (digitalRead (trigPin));
Delay (200);
Triger();
durationB = pulseIn (echoPinB, HIGH);
distanceB = /29.1 (durationB/2);
Serial.Print ("nuevo =");
Serial.println (distanceB);
Serial.Print ("Triger =");
Serial.println (digitalRead (trigPin));
Delay (200);
Si (distanceL < = dSelValue || distanceF < = dSelValue || distanceR < = dSelValue || distanceB < = dSelValue) {}
para (int veces = 1; veces < = 8; veces ++) {}
Serial.println (veces);
digitalWrite (vibración, alta);
digitalWrite (13, HIGH);
Delay (100);
digitalWrite (vibración, baja);
digitalWrite (13, bajo);
Delay (100);
}
}
}
void triger() {}
digitalWrite (trigPin, LOW);
digitalWrite (13, bajo);
delayMicroseconds (1000);
digitalWrite (trigPin, HIGH);
digitalWrite (13, HIGH);
Serial.Print ("Triger =");
Serial.println (digitalRead (trigPin));
delayMicroseconds (1000);
digitalWrite (trigPin, LOW);
digitalWrite (13, bajo);
}