Library for interfacing with the Parallax Ping))) sensor.
Revision 5:cbe07c09c64c, committed 2014-07-29
- Comitter:
- d34d
- Date:
- Tue Jul 29 02:34:02 2014 +0000
- Parent:
- 4:ddffe9339bb1
- Commit message:
- Add user defined delay between continuous readings.
Changed in this revision
ping.cpp | Show annotated file Show diff for this revision Revisions of this file |
ping.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r ddffe9339bb1 -r cbe07c09c64c ping.cpp --- a/ping.cpp Mon Jul 28 00:17:57 2014 +0000 +++ b/ping.cpp Tue Jul 29 02:34:02 2014 +0000 @@ -1,7 +1,8 @@ #include "ping.h" Ping::Ping(PinName signalPin) : mSignalIo(signalPin), mEvent(signalPin), - mBusy(0), mValid(0), mContinuous(0), mTimer(), mRawReading(0) { + mBusy(0), mValid(0), mContinuous(0), + mDelayBetweenReadings(DEFAULT_MEASUREMENT_DELAY_US), mTimer(), mRawReading(0) { mEvent.rise(this, &Ping::start); mEvent.fall(this, &Ping::stop); } @@ -39,7 +40,7 @@ mRawReading = mTimer.read_us() >> 1; mTimer.stop(); mCallback.call(mRawReading); - if (mContinuous) mMeasureDelayTicker.attach_us(this, &Ping::nextMeasurement, 5000); + if (mContinuous) mMeasureDelayTicker.attach_us(this, &Ping::nextMeasurement, mDelayBetweenReadings); } void Ping::nextMeasurement() {
diff -r ddffe9339bb1 -r cbe07c09c64c ping.h --- a/ping.h Mon Jul 28 00:17:57 2014 +0000 +++ b/ping.h Tue Jul 29 02:34:02 2014 +0000 @@ -4,9 +4,9 @@ #include "mbed.h" #include "FPointer.h" -#define MEASUREMENT_DELAY_US 200 -#define SPEED_OF_SOUND_CM_PER_US 0.034029 -#define SPEED_OF_SOUND_IN_PER_US 0.0133972441 +#define DEFAULT_MEASUREMENT_DELAY_US 5000 +#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 @@ -58,6 +58,13 @@ uint32_t getRawReading() { return mRawReading; } /** + * Sets the delay between continuous readings. + * + * @param delay_us Delay between readings in microseconds. + */ + void setContinuousReadingDelay(uint32_t delay_us) { mDelayBetweenReadings = delay_us; } + + /** * Gets the distance sound can travel, in centimeters, for a given time in uS. * * @param time_us Time traveled in microseconds. @@ -96,6 +103,7 @@ bool mBusy; bool mValid; bool mContinuous; + uint32_t mDelayBetweenReadings; Timer mTimer; Ticker mMeasureDelayTicker;