/// <summary> /// Gets the distance. /// </summary> /// <returns>The distance.</returns> public Length GetDistance() { triggerPin.Write(true); Timer.Sleep(triggerTime); triggerPin.Write(false); var upTime = echoPin.Time(true, echoUpTimeout, Timeout); return(Units.Velocity.Sound.ToDistance(upTime) / 2); }
public double getDistance() { double dist = -1; do { try { triggerPin.Write(true); Timer.Sleep(triggerTime); triggerPin.Write(false); var upTime = echoPin.Time(true, echoUpTimeout, Timeout); dist = ((upTime < TimeSpan.Zero) ? (double.MinValue) : ((upTime.TotalMilliseconds) / 1000.0 * 343.8 * 100) / 2.0); } catch (TimeoutException) { } } while (dist < 0); return(dist); }
/// <summary> /// Gets the distance. /// </summary> /// <returns>The distance.</returns> public Length GetDistance() { //for (int i = 1; i < 1000; i++) //{ // triggerPin.Write(true); // Timer.Sleep(triggerTime); // triggerPin.Write(false); // Timer.Sleep(triggerTime); //} triggerPin.Write(true); Timer.Sleep(triggerTime); triggerPin.Write(false); var upTime = echoPin.Time(true, echoUpTimeout, Timeout); return(Units.Velocity.Sound.ToDistance(upTime) / 2); }