upm  1.5.0
Sensor/Actuator repository for libmraa (v1.8.0)
Public Member Functions

API for the HC-SR04 Ultrasonic Sensor. More...

Detailed Description

This module defines the HC-SR04 interface for libhcsr04

main(int argc, char** argv)
upm::HCSR04 sonar(2, 4);
signal(SIGINT, sig_handler);
while (shouldRun) {
std::cout << "get distance" << std::endl;
double distance = sonar.getDistance(HCSR04_CM);
std::cout << "distance " << distance << std::endl;
std::cout << "Exiting... " << std::endl;
return 0;

Public Member Functions

 HCSR04 (int triggerPin, int echoPin)
 ~HCSR04 ()
double getDistance (HCSR04_U unit)

Constructor & Destructor Documentation

HCSR04 ( int  triggerPin,
int  echoPin 

Instantiates an HCSR04 object

triggerPinPin to trigger the sensor for distance
echoPinPulse response to triggering
~HCSR04 ( )

HCSR04 object destructor

Here is the call graph for this function:

Member Function Documentation

double getDistance ( HCSR04_U  unit)

Gets the distance from the sensor

unitSelects units for measurement

Here is the call graph for this function:

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