upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Public Member Functions | Data Fields

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

Detailed Description

This module defines the HC-SR04 interface for libhcsr04

int
main(int argc, char **argv)
{
sonar = new upm::HCSR04(5, 6);
signal(SIGINT, sig_handler);
sleep(1);
for(;;){
std::cout << "get distance" << std::endl;
double distance = sonar->getDistance(CM);
std::cout << "distance " << distance << std::endl;
sleep(5);
}
delete sonar;
return 0;
}

Public Member Functions

 HCSR04 (uint8_t triggerPin, uint8_t echoPin)
 
 ~HCSR04 ()
 
double getDistance (int sys)
 
std::string name ()
 

Data Fields

uint8_t m_doWork
 

Constructor & Destructor Documentation

HCSR04 ( uint8_t  triggerPin,
uint8_t  echoPin 
)

Instantiates an HCSR04 object

Parameters
triggerPinPin to trigger the sensor for distance
echoPinPulse response to triggering
fptrFunction pointer to handle rising-edge and falling-edge interrupts
~HCSR04 ( )

HCSR04 object destructor

Member Function Documentation

double getDistance ( int  sys)

Gets the distance from the sensor

std::string name ( )
inline

Returns the name of the sensor

Field Documentation

uint8_t m_doWork

Flag to control blocking function while waiting for a falling-edge interrupt


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