Library for using HC-SR04 with some API Documentation added
Fork of HC_SR04_Ultrasonic_Library by
ultrasonic Class Reference
ultrasonic class. More...
#include <ultrasonic.h>
Public Member Functions | |
ultrasonic (PinName trigPin, PinName echoPin, float updateSpeed, float timeout) | |
iniates the class with the specified trigger pin, echo pin, update speed and timeout | |
ultrasonic (PinName trigPin, PinName echoPin, float updateSpeed, float timeout, void onUpdate(int)) | |
iniates the class with the specified trigger pin, echo pin, update speed, timeout and method to call when the distance changes | |
int | getCurrentDistance (void) |
returns the last measured distance | |
void | pauseUpdates (void) |
auses measuring the distance | |
void | startUpdates (void) |
tarts mesuring the distance | |
void | attachOnUpdate (void method(int)) |
attachs the method to be called when the distances changes | |
void | changeUpdateSpeed (float updateSpeed) |
Method: changes the speed at which updates are made. | |
int | isUpdated (void) |
gets whether the distance has been changed since the last call of isUpdated() or checkDistance() | |
float | getUpdateSpeed (void) |
gets the speed at which updates are made | |
void | checkDistance (void) |
call this as often as possible in your code, eg. |
Detailed Description
ultrasonic class.
Used for HC-SR04 ultrasonic range sensor
Example:
#include "mbed.h" #include "ultrasonic.h" ultrasonic usensor(PA_6, PA_7, 0.1, 0.25, &dist); int main() { //start mesuring the distance usensor.startUpdates(); while(1){ usensor.checkDistance(); } }
Definition at line 25 of file ultrasonic.h.
Constructor & Destructor Documentation
ultrasonic | ( | PinName | trigPin, |
PinName | echoPin, | ||
float | updateSpeed, | ||
float | timeout | ||
) |
iniates the class with the specified trigger pin, echo pin, update speed and timeout
- Parameters:
-
trigPin The "trigger" pin for the ultrasonic sensor. This is DigitalOut. echoPin The "echo" pin for the ultrasonic sensor. This is InterruptIn. updateSpeed How often the ultrasonic sensor pings and listens for a response. timeout How long to wait before giving up on listening for a ping.
Definition at line 3 of file ultrasonic.cpp.
ultrasonic | ( | PinName | trigPin, |
PinName | echoPin, | ||
float | updateSpeed, | ||
float | timeout, | ||
void | onUpdateint | ||
) |
iniates the class with the specified trigger pin, echo pin, update speed, timeout and method to call when the distance changes
- Parameters:
-
trigPin The "trigger" pin for the ultrasonic sensor. This is DigitalOut. echoPin The "echo" pin for the ultrasonic sensor. This is InterruptIn. updateSpeed How often the ultrasonic sensor pings and listens for a response. timeout How long to wait before giving up on listening for a ping. onUpdate(int) The function to be called when the distance is detected to have changed.
Definition at line 9 of file ultrasonic.cpp.
Member Function Documentation
void attachOnUpdate | ( | void | methodint ) |
attachs the method to be called when the distances changes
- Parameters:
-
method(int) The function to be called when the distance is detected to have changed.
Definition at line 61 of file ultrasonic.cpp.
void changeUpdateSpeed | ( | float | updateSpeed ) |
Method: changes the speed at which updates are made.
- Parameters:
-
updateSpeed how often to update the ultrasonic sensor
Definition at line 65 of file ultrasonic.cpp.
void checkDistance | ( | void | ) |
call this as often as possible in your code, eg.
at the end of a while(1) loop, and it will check whether the method you have attached needs to be called
Definition at line 80 of file ultrasonic.cpp.
int getCurrentDistance | ( | void | ) |
returns the last measured distance
Definition at line 47 of file ultrasonic.cpp.
float getUpdateSpeed | ( | void | ) |
gets the speed at which updates are made
Definition at line 69 of file ultrasonic.cpp.
int isUpdated | ( | void | ) |
gets whether the distance has been changed since the last call of isUpdated() or checkDistance()
Definition at line 73 of file ultrasonic.cpp.
void pauseUpdates | ( | void | ) |
auses measuring the distance
Definition at line 51 of file ultrasonic.cpp.
void startUpdates | ( | void | ) |
tarts mesuring the distance
Definition at line 57 of file ultrasonic.cpp.
Generated on Wed Jul 13 2022 06:28:11 by 1.7.2