PetCare
|
Class for handling ultrasonic distance measurement using an ultrasonic sensor. More...
Public Member Functions | |
UltrasonicSensor (int triggerPin, int echoPin) | |
Constructor for UltrasonicSensor. | |
~UltrasonicSensor () | |
Destructor for UltrasonicSensor. | |
void | startMeasurement () |
Start the distance measurement process. | |
void | stop () |
Stop the distance measurement process. | |
void | setDistanceCallback (std::function< void(float)> callback) |
Set the callback function to be called when distance is measured. | |
Class for handling ultrasonic distance measurement using an ultrasonic sensor.
This class provides functionality to measure distance using an ultrasonic sensor by triggering pulses and listening for an echo response.
UltrasonicSensor::UltrasonicSensor | ( | int | triggerPin, |
int | echoPin ) |
Constructor for UltrasonicSensor.
triggerPin | GPIO pin number used to trigger the sensor. |
echoPin | GPIO pin number used to receive the echo from the sensor. |
void UltrasonicSensor::setDistanceCallback | ( | std::function< void(float)> | callback | ) |
Set the callback function to be called when distance is measured.
callback | The function to call with the measured distance. |
void UltrasonicSensor::startMeasurement | ( | ) |
Start the distance measurement process.
Starts a new thread that continuously measures distance until stopped.
void UltrasonicSensor::stop | ( | ) |
Stop the distance measurement process.
Stops the measurement thread and cleans up resources.