Been messing around a bit more with the (4X Ping) code. Unfortunately something isn't cooperating ![]()
Atm, getting (0in, 0in, 0in, 0in) in serial monitor...and the scrolling/updating is a bit slow.
// 4 Ping sensor code for left, right, rear & head ping sensors mounted on robot.
// Using Arduino Mega 2560 & IDE 1.0.1
//
// 10June12
#define LT_PING 20
#define RT_PING 21
#define RR_PING 22
#define HD_PING 23
long in1 = 0;
long in2 = 0;
long in3 = 0;
long in4 = 0;
//const int buzzPin = 4;
void setup()
{
 Serial.begin(9600);
 //pinMode(buzzPin, OUTPUT);
}
long ping(int pin)
{
 pinMode(pin, OUTPUT);
 digitalWrite(pin, LOW);
 delayMicroseconds(2);
 digitalWrite(pin, HIGH);
 delayMicroseconds(5);
 digitalWrite(pin, LOW);
 pinMode(pin, INPUT);
Â
long duration = pulseIn(pin, HIGH);
Â
 return (microsecondsToInches(duration));
}
long microsecondsToInches(long microseconds)
{
 return microseconds / 74 / 2;
}
void loop()
{
 in1 = ping(LT_PING);
 delay(5);
 in2 = ping(RT_PING);
 delay(5);
 in3 = ping(RR_PING);
 delay(5);
 in4 = ping(HD_PING);
 delay(5);
Â
 Serial.print(in1);
 Serial.print("in, ");
 Serial.print(in2);
 Serial.print("in, ");
 Serial.print(in3);
 Serial.print("in, ");
 Serial.print(in4);
 Serial.print("in, ");
 Serial.println();
 Â
}
// Use buzzer, main motors to react to different Ping threshold distances
 //digitalWrite(buzzPin, LOW); Â
 //if(in1 < 24) digitalWrite(buzzPin, HIGH);  // sets a min. threshold value of 24" to sound alarm for Left Ping sensor
 //if(in2 < 24) digitalWrite(buzzPin, HIGH);  // sets a min. threshold value of 24" to sound alarm for Right Ping sensor
 //if(in3 < 18) digitalWrite(buzzPin, HIGH);  // sets a min. threshold value of 18" to sound alarm for Rear Ping sensor
 //if(in4 < 60) digitalWrite(buzzPin, HIGH);  // sets a min. threshold value of 60" to sound alarm for Head Ping sensor
thomas