First Draft, serial print change based on distance
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) |
| pauses measuring the distance | |
| void | startUpdates (void) |
| starts mesuring the distance | |
| void | attachOnUpdate (void method(int)) |
| attachs the method to be called when the distances changes | |
| void | changeUpdateSpeed (float updateSpeed) |
| 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.
Acknowledgements to EJ Teb Library for interfacing with ultrasonic sensor
Example:
#include "mbed.h" #include "ultrasonic.h" void dist(int distance) { printf("Distance changed to %dmm\r\n", distance); } ultrasonic mu(PTD0, PTC12, .1, 1, &dist); //Set the trigger pin to PTD0 and the echo pin to PTC12 //have updates every .1 seconds and a timeout after 1 //second, and call dist when the distance changes int main() { mu.startUpdates();//start mesuring the distance while(1) { //Do something else here mu.checkDistance(); //call checkDistance() as much as possible, as this is where //the class checks if dist needs to be called. } }
Definition at line 43 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
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
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
Definition at line 61 of file ultrasonic.cpp.
| void changeUpdateSpeed | ( | float | updateSpeed ) |
changes the speed at which updates are made
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 | ) |
pauses measuring the distance
Definition at line 51 of file ultrasonic.cpp.
| void startUpdates | ( | void | ) |
starts mesuring the distance
Definition at line 57 of file ultrasonic.cpp.
Generated on Mon Aug 22 2022 16:53:08 by
1.7.2