MBSD_assignment / Ultrasonic

Dependents:   test_ultrasonic AEB Car_Simulator

Embed: (wiki syntax)

« Back to documentation index

Ultrasonic Class Reference

Ultrasonic Class Reference

Ultrasonic Class This class is intended to be used with a ultrasonic sensor HC-SR04. More...

#include <Ultrasonic.h>

Public Member Functions

 Ultrasonic (PinName trigger, PinName echo)
 Constructor.
int read_cm ()
 Function to read the distance in cm.

Detailed Description

Ultrasonic Class This class is intended to be used with a ultrasonic sensor HC-SR04.

Once initialized the Ultrasonic object just call the read function to get the distance from object.

Definition at line 12 of file Ultrasonic.h.


Constructor & Destructor Documentation

Ultrasonic ( PinName  trigger,
PinName  echo 
)

Constructor.

Note:
This is used to initialize the ultrasonic object corresponding to one sensor, just pass as input the pin where the sensor is connected (they must be digital pins).
Parameters:
triggerthe trigger pin name
echothe echo pin name

Definition at line 5 of file Ultrasonic.cpp.


Member Function Documentation

int read_cm (  )

Function to read the distance in cm.

Note:
the distance is read internally every 60 ms so invoke this function not less than every 60 ms
Returns:
0 if timeout(50ms) elapsed (error or out of range measure), 1-400 distance from object in cm

Definition at line 10 of file Ultrasonic.cpp.