Easyuino  1.2.0
Easyuino::DistanceMeter Class Reference

Used to represent the at least supported Ultrasonic Module models enum UltrasonicModule : uint8_t { HC_SR03, HC_SR04, HC_SR05 };. More...

#include <DistanceMeter.h>

Inheritance diagram for Easyuino::DistanceMeter:
Easyuino::Device Easyuino::DistanceMeterNonBlock Easyuino::DistanceMeterPrintable Easyuino::DistanceMeterAccurate

Public Member Functions

 DistanceMeter (IN uint8_t triggerPin, IN uint8_t echoPin)
 Constructor. More...
 
 DistanceMeter (IN uint8_t triggerEchoPin)
 Contructor used with Ultrasonic Modules that have only one pin for trigger and echo. More...
 
 ~DistanceMeter ()
 Destructor.
 
bool begin ()
 Used to put the device ready to receive requests. More...
 
void end ()
 Used to stop the device API. More...
 
virtual float getDistanceCentimeters ()
 Gets the last value that the API measured using the Ultrasonic Module. More...
 
float getDistanceInches ()
 Gets the last value that the API measured using the US. More...
 
virtual void updateDistance ()
 Updates the distance of the Ultrasonic Module to the objects in a blocking way. More...
 
- Public Member Functions inherited from Easyuino::Device
 Device ()
 Constructor called by every sub-classes.
 
 ~Device ()
 Destroy all the resources associated with the device.
 
bool isInitialized () const
 Verify is the device is initialized and ready to use. More...
 

Protected Member Functions

float executeUpdateDistanceBlock (IN float soundSpeed)
 Execute a block distance measurement and calculates the distance based on the sound speed. More...
 

Protected Attributes

uint8_t _triggerPin
 Arduino pin used to trigger the echo wave emission.
 
uint8_t _echoPin
 Arduino pin that is set to LOW by when reflected echo wave arrives.
 
volatile bool _isEchoing
 Used to know if it is in a middle of a measurement.
 
volatile float _distance
 It contains a cached value of the last distance measured. More...
 
- Protected Attributes inherited from Easyuino::Device
bool _isInitialized
 Used to know if the device API is initialized and ready to receive requests.
 

Detailed Description

Used to represent the at least supported Ultrasonic Module models enum UltrasonicModule : uint8_t { HC_SR03, HC_SR04, HC_SR05 };.

DistanceMeter offers a simple API to interact with an Ultrasonic Module to measure distances to objects.

See also
Devices Supported: HC-SR03, HC-SR04, HC-SR05
Devices Tested: HC-SR04

Constructor & Destructor Documentation

◆ DistanceMeter() [1/2]

Easyuino::DistanceMeter::DistanceMeter ( IN uint8_t  triggerPin,
IN uint8_t  echoPin 
)

Constructor.

Parameters
triggerPinArduino pin connected to the trigger pin of the Ultrasonic Module
echoPinArduino pin connected to the echo pin of the Ultrasonic Module

◆ DistanceMeter() [2/2]

Easyuino::DistanceMeter::DistanceMeter ( IN uint8_t  triggerEchoPin)

Contructor used with Ultrasonic Modules that have only one pin for trigger and echo.

Parameters
triggerEchoPinArduino pin connected to the trigger&echo pin of the Ultrasonic Module

Member Function Documentation

◆ begin()

bool Easyuino::DistanceMeter::begin ( )
virtual

Used to put the device ready to receive requests.

Normally this have some default behaviour some devices have other overload method with same name that receives other arguments to device customization.

Returns
True: If the device was initialized. False: Otherwise.

Implements Easyuino::Device.

Reimplemented in Easyuino::DistanceMeterNonBlock.

◆ end()

void Easyuino::DistanceMeter::end ( )
virtual

Used to stop the device API.

After this the the device will not process API requests.

Implements Easyuino::Device.

Reimplemented in Easyuino::DistanceMeterNonBlock.

◆ executeUpdateDistanceBlock()

float Easyuino::DistanceMeter::executeUpdateDistanceBlock ( IN float  soundSpeed)
protected

Execute a block distance measurement and calculates the distance based on the sound speed.

Parameters
soundSpeed(Cm/Sec) Sound speed to introduce in the calculation
Returns
distance (Centimeters) The new distance measured

◆ getDistanceCentimeters()

virtual float Easyuino::DistanceMeter::getDistanceCentimeters ( )
virtual

Gets the last value that the API measured using the Ultrasonic Module.

Returns
distance (Centimeters) The most recent measurement the API have done

Reimplemented in Easyuino::DistanceMeterNonBlock, and Easyuino::DistanceMeterAccurate.

◆ getDistanceInches()

float Easyuino::DistanceMeter::getDistanceInches ( )

Gets the last value that the API measured using the US.

Returns
distance (Inches) The most recent measurement the API have done

◆ updateDistance()

virtual void Easyuino::DistanceMeter::updateDistance ( )
virtual

Updates the distance of the Ultrasonic Module to the objects in a blocking way.

The new distance value is available using getDistanceCentimeters() or getDistanceInches() method after calling this method.

Warning
This method blocks while the measurement is on going, so the arduino waits for the measure to be concluded, if you want a non block update distance method look for DistanceMeterNonBlock API

Reimplemented in Easyuino::DistanceMeterNonBlock.

Member Data Documentation

◆ _distance

volatile float Easyuino::DistanceMeter::_distance
protected

It contains a cached value of the last distance measured.

Avoid calculate all the time.


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