Rpi-hw  0.7.2
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
rpihw::sensor::hcsr04 Class Reference

Ultrasonic distance sensor HC-SR04. More...

#include <hcsr04.hpp>

Public Types

using timer = high_resolution_clock
 Used timer to measure the delay of pulse.
 

Public Member Functions

 hcsr04 (uint8_t trigger, uint8_t echo)
 Constructor method. More...
 
virtual ~hcsr04 ()
 Destructor method.
 
double timing ()
 Returns the elapsed time between sending and receiving back the pulse. More...
 
double ranging ()
 Returns the distance from the sensor to an object or surface. More...
 

Protected Attributes

iface::outputm_trigger
 Output interface to the trigger.
 
iface::inputm_echo
 Input interface connected to the echo pin.
 
std::chrono::time_point< timerm_last_sending
 Time of last pulse sending.
 

Detailed Description

Ultrasonic distance sensor HC-SR04.

Examples:
sensor/hcsr04.cpp.

Definition at line 57 of file hcsr04.hpp.

Constructor & Destructor Documentation

rpihw::sensor::hcsr04::hcsr04 ( uint8_t  trigger,
uint8_t  echo 
)

Constructor method.

Parameters
[in]triggerThe GPIO pin connected to the trigger.
[in]echoThe GPIO pin connected to the echo pin.

Member Function Documentation

double rpihw::sensor::hcsr04::ranging ( )
inline

Returns the distance from the sensor to an object or surface.

Returns
The distance in centimeters.
Examples:
sensor/hcsr04.cpp.

Definition at line 30 of file hcsr04-inl.hpp.

double rpihw::sensor::hcsr04::timing ( )

Returns the elapsed time between sending and receiving back the pulse.

Returns
The elapsed time in milliseconds.
Examples:
sensor/hcsr04.cpp.

The documentation for this class was generated from the following files: