Library for interfacing with the Parallax Ping))) sensor.
Diff: ping.h
- Revision:
- 3:0c337c262d84
- Parent:
- 1:72fbcb01291d
- Child:
- 4:ddffe9339bb1
--- a/ping.h Sun Jul 27 19:55:41 2014 +0000 +++ b/ping.h Mon Jul 28 00:16:34 2014 +0000 @@ -4,7 +4,9 @@ #include "mbed.h" #include "FPointer.h" -#define MEASUREMENT_DELAY_US 200 +#define MEASUREMENT_DELAY_US 200 +#define SPEED_OF_SOUND_CM_PER_US 0.034029 +#define SPEED_OF_SOUND_IN_PER_US 0.0133972441 /** * Class for interfacing with the Parallax Ping))) Ultrasonic Sensor @@ -56,6 +58,22 @@ uint32_t getRawReading() { return mRawReading; } /** + * Gets the distance sound can travel, in centimeters, for a given time in uS. + * + * @param time_us Time traveled in microseconds. + * @return The distance traveled in centimeters. + */ + float getDistanceCm(uint32_t time_us) { return time_us * SPEED_OF_SOUND_CM_PER_US; } + + /** + * Gets the distance sound can travel, in inches, for a given time in uS. + * + * @param time_us Time traveled in microseconds. + * @return The distance traveled in inches. + */ + float getDistanceIn(uint32_t time_us) { return time_us * SPEED_OF_SOUND_IN_PER_US; } + + /** * Attach a callback function that will be called when a valid reading is available. * * @param function Function pointer for callback. @@ -79,7 +97,6 @@ bool mValid; bool mContinuous; - uint32_t mStartTime; Timer mTimer; Ticker mMeasureDelayTicker;