upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions

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

Detailed Description

This module defines the HC-SR04 interface for libhcsr04

groveultrasonic.jpg
int
main(int argc, char** argv)
{
upm::HCSR04 sonar(2, 4);
signal(SIGINT, sig_handler);
upm_delay(1);
while (shouldRun) {
std::cout << "get distance" << std::endl;
double distance = sonar.getDistance(HCSR04_CM);
std::cout << "distance " << distance << std::endl;
upm_delay(2);
}
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

Parameters
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

Parameters
unitSelects units for measurement

Here is the call graph for this function:


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