NewPing Library: HC-SR04, SRF05, SRF06, DYP-ME007, Parallax PING))) - v1.7

AWOL:

basile-laderchi:
This is part of the sketch I am using:

This is part of an answer I am giving: tone.

That's exactly why I replaced the tone function with this function:

void toneWorkaround(byte tonePin, int frequency, int duration) {
  int period = 1000000L / frequency;
  int pulse = period / 2;
  for (long i = 0; i < duration * 1000L; i += period) {
    digitalWrite(tonePin, HIGH);
    delayMicroseconds(pulse);
    digitalWrite(tonePin, LOW);
    delayMicroseconds(pulse);
  }
}

Even after this modification to my code though the Parallax PING))) refuses to work when using the NewPing library.

Right now the Parallax PING))) is working and returning correct values with this code:

long ping(byte pingPin) {
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  pinMode(pingPin, INPUT);
  long duration = pulseIn(pingPin, HIGH);
  return duration;
}

basile

P.S.: robot's full code as is right now: Wheeled-Robot Arduino Code - Pastebin.com