upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Member Functions
GroveUltraSonic Class Reference

API for Grove Ultrasonic Ranger. More...

Detailed Description

This Grove Ultrasonic sensor is a non-contact distance measurement module which is compatible with the Grove system. It is designed for easy modular project usage with industrial performance. Detection ranges from 3 cm (1.2") to 4 m (13'1.5") and works best when the object is within a 30 degree angle relative to the sensor.

groveultrasonic.jpg
// upm::GroveUltraSonic *sonar = NULL;
sonar = new upm::GroveUltraSonic(2);
while(running) {
int width = sonar->getDistance();
printf("Echo width = %d\n", width);
printf("Distance inches = %f.2\n\n", width/148.0);
sleep(3);
}

Public Member Functions

 GroveUltraSonic (uint8_t pin)
 
 ~GroveUltraSonic ()
 
int getDistance ()
 
std::string name ()
 
bool working ()
 

Constructor & Destructor Documentation

GroveUltraSonic ( uint8_t  pin)

Instantiates a GroveUltraSonic object

Parameters
pinpin for triggering the sensor for distance and for receiving pulse response

GroveUltraSonic object destructor.

Member Function Documentation

int getDistance ( )

Returns the echo's pulse width from the sensor in microseconds. Divide by 58 to convert distance to centimetres. Divide by 148 to convert distance to inches.

std::string name ( )
inline

Return name of the component

bool working ( )
inline

Returns true while the sensor is busy waiting for the echo pulse


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