I am trying to get values for two ping sensors, but am not getting any returns, can someone help me edit my code?
Code
void setup()
{
Serial.begin(9600);
pingRange(2);
pingRange(3);
}
void loop(){
}
long pingRange (int pingPin)
{
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
return microsecondsToCentimeters(pulseIn(pingPin, HIGH));
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}