upm  1.3.0
Sensor/Actuator repository for libmraa (v1.7.0)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions
HCSR04 Class Reference

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 = new upm::HCSR04(2, 4);
signal(SIGINT, sig_handler);
sleep(1);
while(shouldRun){
std::cout << "get distance" << std::endl;
double distance = sonar->getDistance(HCSR04_CM);
std::cout << "distance " << distance << std::endl;
sleep(2);
}
std::cout << "Exiting... " << std::endl;
delete sonar;
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: