PetCare
Loading...
Searching...
No Matches
Public Member Functions | List of all members
UltrasonicSensor Class Reference

Class for handling ultrasonic distance measurement using an ultrasonic sensor. More...

Collaboration diagram for UltrasonicSensor:
Collaboration graph

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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ UltrasonicSensor()

UltrasonicSensor::UltrasonicSensor ( int triggerPin,
int echoPin )

Constructor for UltrasonicSensor.

Parameters
triggerPinGPIO pin number used to trigger the sensor.
echoPinGPIO pin number used to receive the echo from the sensor.

Member Function Documentation

◆ setDistanceCallback()

void UltrasonicSensor::setDistanceCallback ( std::function< void(float)> callback)

Set the callback function to be called when distance is measured.

Parameters
callbackThe function to call with the measured distance.

◆ startMeasurement()

void UltrasonicSensor::startMeasurement ( )

Start the distance measurement process.

Starts a new thread that continuously measures distance until stopped.

◆ stop()

void UltrasonicSensor::stop ( )

Stop the distance measurement process.

Stops the measurement thread and cleans up resources.


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