Library for interfacing with the Parallax Ping))) sensor.
Dependencies:
FPointer
« Back to documentation index
Ping Class Reference
Class for interfacing with the Parallax Ping ))) Ultrasonic Sensor.
More...
#include <ping.h >
Public Member Functions
Ping (PinName pin)
bool startReading ()
Starts a one shot reading.
bool startReading (bool continuous)
Starts a reading.
bool isBusy ()
Returns whether the sensor is busy getting a reading.
bool isValid ()
Returns whether the valid reading is available.
uint32_t getRawReading ()
Returns the raw reading from the sensor.
void setContinuousReadingDelay (uint32_t delay_us)
Sets the delay between continuous readings.
void attach (uint32_t(*function)(uint32_t)=0)
Attach a callback function that will be called when a valid reading is available.
template<class T >
void attach (T *item, uint32_t(T::*method)(uint32_t))
Attach a class method that will be called when a valid reading is available.
Static Public Member Functions
static float getDistanceCm (uint32_t time_us)
Gets the distance sound can travel, in centimeters, for a given time in uS.
static float getDistanceIn (uint32_t time_us)
Gets the distance sound can travel, in inches, for a given time in uS.
Detailed Description
Class for interfacing with the Parallax Ping ))) Ultrasonic Sensor.
See the Ping )) documentation for more information. http://www.parallax.com/sites/default/files/downloads/28015-PING-Documentation-v1.6.pdf
Definition at line 17 of file ping.h .
Constructor & Destructor Documentation
Parameters:
pin Digital I/O pin used for communicating with the Ping )))
Definition at line 3 of file ping.cpp .
Member Function Documentation
void attach
(
uint32_t(*)(uint32_t)
function = 0 )
Attach a callback function that will be called when a valid reading is available.
Parameters:
function Function pointer for callback.
Definition at line 88 of file ping.h .
void attach
(
T *
item ,
uint32_t(T::*)(uint32_t)
method
)
Attach a class method that will be called when a valid reading is available.
Parameters:
item Class object that contains the method to call.
method Method to call.
Definition at line 97 of file ping.h .
static float getDistanceCm
(
uint32_t
time_us )
[static]
Gets the distance sound can travel, in centimeters, for a given time in uS.
Parameters:
time_us Time traveled in microseconds.
Returns: The distance traveled in centimeters.
Definition at line 73 of file ping.h .
static float getDistanceIn
(
uint32_t
time_us )
[static]
Gets the distance sound can travel, in inches, for a given time in uS.
Parameters:
time_us Time traveled in microseconds.
Returns: The distance traveled in inches.
Definition at line 81 of file ping.h .
uint32_t getRawReading
(
)
Returns the raw reading from the sensor.
Returns: The time in uS that the sound travelled from the sensor to an object.
Definition at line 58 of file ping.h .
Returns whether the sensor is busy getting a reading.
Returns: True if busy, false if not.
Definition at line 44 of file ping.h .
Returns whether the valid reading is available.
Returns: True if valid, false if not.
Definition at line 51 of file ping.h .
void setContinuousReadingDelay
(
uint32_t
delay_us )
Sets the delay between continuous readings.
Parameters:
delay_us Delay between readings in microseconds.
Definition at line 65 of file ping.h .
bool startReading
(
bool
continuous )
Starts a reading.
Parameters:
continuous Continuous readings if true, one-shot if false.
Returns: True if the reading was successfuly started, false if not.
Definition at line 14 of file ping.cpp .
Starts a one shot reading.
Returns: True if the reading was successfuly started, false if not.
Definition at line 10 of file ping.cpp .