PropWare  3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Public Member Functions | List of all members
PropWare::Ping Class Reference

Ultrasonic distance sensor such as the Parallax PING))) More...

#include <PropWare/sensor/distance/ping.h>

+ Inheritance diagram for PropWare::Ping:

Public Member Functions

 Ping (const PropWare::Pin::Mask signalMask)
 Construct an instance for a 3-pin variant such as the Parallax PING))) sensor. More...
 
 Ping (const PropWare::Pin::Mask triggerMask, const PropWare::Pin::Mask echoMask)
 Construct an instance for a 4-pin variant, commonly found on eBay. More...
 
unsigned int get_millimeters () const
 Detect distance as measured in millimeters between sensor and object. More...
 
unsigned int get_centimeters () const
 Detect distance as measured in centimeters between sensor and object. More...
 
unsigned int get_inches () const
 Detect distance as measured in inches between sensor and object. More...
 
unsigned int get_microseconds () const
 Time measured in microseconds for a sound wave to travel from the sensor to an object and back. More...
 
unsigned int get_clock_ticks () const
 Time measured in system clock ticks for a sound wave to travel from the sensor to an object and back. This is the most accurate method on the Ping class. More...
 

Detailed Description

Ultrasonic distance sensor such as the Parallax PING)))

For 3-pin variants like the Parallax PING))) sensor, use the following template:

int main () {
// Propeller pin P01 connected to the signal line of the PING)))
const PropWare::Ping ping(PropWare::Pin::P01);
unsigned int centimeters = ping.get_centimeters();
// User code here...
pwOut << centimeters << '\n';
return 0;
}
Examples
Ping_Demo.cpp.

Definition at line 54 of file ping.h.

Constructor & Destructor Documentation

◆ Ping() [1/2]

PropWare::Ping::Ping ( const PropWare::Pin::Mask  signalMask)

Construct an instance for a 3-pin variant such as the Parallax PING))) sensor.

Parameters
[in]signalMaskPin mask for the signal pin of the sensor

Definition at line 61 of file ping.h.

◆ Ping() [2/2]

PropWare::Ping::Ping ( const PropWare::Pin::Mask  triggerMask,
const PropWare::Pin::Mask  echoMask 
)

Construct an instance for a 4-pin variant, commonly found on eBay.

Parameters
[in]triggerMaskPin mask for the trigger pin
[in]echoMaskPin mask for the echo pin

Definition at line 72 of file ping.h.

Member Function Documentation

◆ get_centimeters()

unsigned int PropWare::Ping::get_centimeters ( ) const

Detect distance as measured in centimeters between sensor and object.

Returns
Centimeters between sensor and object. Fractional values are truncated.

Definition at line 95 of file ping.h.

+ Here is the call graph for this function:

◆ get_clock_ticks()

unsigned int PropWare::Ping::get_clock_ticks ( ) const

Time measured in system clock ticks for a sound wave to travel from the sensor to an object and back. This is the most accurate method on the Ping class.

Returns
Clock ticks for a round trip.

Definition at line 127 of file ping.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_inches()

unsigned int PropWare::Ping::get_inches ( ) const

Detect distance as measured in inches between sensor and object.

Returns
Inches between sensor and object. Fractional values are truncated.

Definition at line 104 of file ping.h.

+ Here is the call graph for this function:

◆ get_microseconds()

unsigned int PropWare::Ping::get_microseconds ( ) const

Time measured in microseconds for a sound wave to travel from the sensor to an object and back.

Returns
Microseconds for a round trip. Fractional values are truncated.

Definition at line 113 of file ping.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_millimeters()

unsigned int PropWare::Ping::get_millimeters ( ) const

Detect distance as measured in millimeters between sensor and object.

Note
Ultrasonic sensors and the Parallax Propeller are not accurate enough for 1 mm precision. This method is only provided to give a finer grain of precision than Ping::get_centimeters without reverting to floating point numbers.
Returns
Millimeters between sensor and object

Definition at line 86 of file ping.h.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file:
printer.h
PropWare::Ping
Ultrasonic distance sensor such as the Parallax PING)))
Definition: ping.h:54
ping.h
main
int main(void)
Definition: GraphicsTest.c:20
pwOut
PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
ping
int ping(int pin)
Measure echo time in terms of Propeller system clock ticks.
Definition: ping.c:3