DistanceMeterNonBlock offers an API to interact with an Ultrasonic Module to measure distance in a non-block way.
More...
#include <DistanceMeterNonBlock.h>
|
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...
|
|
bool | _isInitialized |
| Used to know if the device API is initialized and ready to receive requests.
|
|
DistanceMeterNonBlock offers an API to interact with an Ultrasonic Module to measure distance in a non-block way.
It offers a the same as DistanceMeter API plus updateDistanceNonBlock() that allows your application code run while the distance is calculated in "background" without stopping your program.
- See also
- Limitation: This allows ONLY 2 instances of DistanceMeterNonBlock per sketch!!
-
Limitation: The accuracy of the non-block method is much smaller because it uses interruption mechanism
-
Devices Supported: HC-SR03, HC-SR04, HC-SR05
-
Devices Tested: HC-SR04
◆ DistanceMeterNonBlock() [1/2]
Easyuino::DistanceMeterNonBlock::DistanceMeterNonBlock |
( |
IN uint8_t |
triggerPin, |
|
|
IN uint8_t |
echoPin |
|
) |
| |
Constructor.
- Parameters
-
triggerPin | Arduino pin connected to the trigger pin of the Ultrasonic Module |
echoPin | Arduino pin connected to the echo pin of the Ultrasonic Module |
◆ DistanceMeterNonBlock() [2/2]
Easyuino::DistanceMeterNonBlock::DistanceMeterNonBlock |
( |
IN uint8_t |
triggerEchoPin | ) |
|
Contructor used with Ultrasonic Modules that have only one pin for trigger and echo.
- Parameters
-
triggerEchoPin | Arduino pin connected to the trigger&echo pin of the Ultrasonic Module |
◆ begin()
bool Easyuino::DistanceMeterNonBlock::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.
Reimplemented from Easyuino::DistanceMeter.
◆ calculateDistance()
float Easyuino::DistanceMeterNonBlock::calculateDistance |
( |
IN float |
soundSpeedCmPerSec | ) |
|
|
protected |
Calculates the distance to the object based on the sound speed in air using the last distance value measured!
- Parameters
-
soundSpeedCmPerSec | (Cm/Sec) The sound speed to be taken in account during the calculation |
- Returns
- distance (Centimeters) The new calculated distance
◆ end()
void Easyuino::DistanceMeterNonBlock::end |
( |
| ) |
|
|
virtual |
Used to stop the device API.
After this the the device will not process API requests.
Reimplemented from Easyuino::DistanceMeter.
◆ getDistanceCentimeters()
float Easyuino::DistanceMeterNonBlock::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 from Easyuino::DistanceMeter.
◆ isUpdateDistanceNonBlockTimeout()
bool Easyuino::DistanceMeterNonBlock::isUpdateDistanceNonBlockTimeout |
( |
| ) |
|
|
protected |
Verify if there is a non-block measuremenet on going that has already timeouted.
- Returns
- True: If it timeout. False: Otherwise.
◆ updateDistance()
void Easyuino::DistanceMeterNonBlock::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 from Easyuino::DistanceMeter.
◆ updateDistanceNonBlock()
virtual void Easyuino::DistanceMeterNonBlock::updateDistanceNonBlock |
( |
| ) |
|
|
virtual |
Updates the distance of the Ultrasonic Module to the objects in a non-blocking way.
This means that the call to the method will return immediatly and in the "background" the distance measure will ocurr after a while. When the measurement is concluded and you call getDistanceCentimeters() or getDistanceInches() the new distance value will be returned. While the measurement is on going the distance will be from the last measurement.
The documentation for this class was generated from the following file: