Uncompiled, untested:
#define N_PINGS 4
const byte pingPins [N_PINGS] = {20, 21, 22, 23};
const int minRanges [N_PINGS] = {24, 24, 18, 60}; // for later.
void setup()
{
Serial.begin(9600);
}
void loop()
{
int range [N_PINGS];
for (int i = 0; i < N_PINGS; ++i) {
range [i] = ping(pingPins [i]);
delay(5);
}
for (int i = 0; i < N_PINGS; ++i) {
Serial.print(range [i]);
Serial.print(" ");
}
Serial.println("inches");
}
long ping(int pin)
{
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
delayMicroseconds(2);
digitalWrite(pin, HIGH);
delayMicroseconds(5);
digitalWrite(pin, LOW);
pinMode(pin, INPUT);
return (microsecondsToInches(pulseIn(pin, HIGH)));
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
Reducing the limit in the "for" loops will allow you to concentrate on just one sensor.