Appendix
29
}
}
void ask_pin_F() // test forward distance
{
myservo.write(90);
digitalWrite(outputPin, LOW);
delayMicroseconds(2);
digitalWrite(outputPin, HIGH);
delayMicroseconds(10);
digitalWrite(outputPin, LOW);
float Fdistance = pulseIn(inputPin, HIGH);
Fdistance= Fdistance/5.8/10;
Serial.print("F distance:");
Serial.println(Fdistance);
Fspeedd = Fdistance;
}
void ask_pin_L() // test left distance
{
myservo.write(5);
delay(delay_time);
digitalWrite(outputPin, LOW);
delayMicroseconds(2);
digitalWrite(outputPin, HIGH);
delayMicroseconds(10);
digitalWrite(outputPin, LOW);
float Ldistance = pulseIn(inputPin, HIGH);
Ldistance= Ldistance/5.8/10;
Serial.print("L distance:");
Serial.println(Ldistance);
Lspeedd = Ldistance;
}
void ask_pin_R() // test right distance
{
myservo.write(177);
delay(delay_time);
digitalWrite(outputPin, LOW);
delayMicroseconds(2);
digitalWrite(outputPin, HIGH);
delayMicroseconds(10);
digitalWrite(outputPin, LOW);
float Rdistance = pulseIn(inputPin, HIGH);
Rdistance= Rdistance/5.8/10;
Serial.print("R distance:");
Serial.println(Rdistance);
Rspeedd = Rdistance;
}
void loop()
{
myservo.write(90);
detection();
if(directionn == 2)
{
back(8);
turnL(2);
Serial.print(" Reverse ");
}