Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of HC_SR04_Ultrasonic_Library by
ultrasonic.h@2:cc1143d36567, 2014-11-24 (annotated)
- Committer:
- ejteb
- Date:
- Mon Nov 24 17:10:44 2014 +0000
- Revision:
- 2:cc1143d36567
- Parent:
- 1:114e0698a5d2
Library working with hello world and documentation and tidy code
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ejteb | 0:6aa04a8c8d4c | 1 | #ifndef MBED_ULTRASONIC_H |
| ejteb | 0:6aa04a8c8d4c | 2 | #define MBED_ULTRASONIC_H |
| ejteb | 0:6aa04a8c8d4c | 3 | |
| ejteb | 0:6aa04a8c8d4c | 4 | #include "mbed.h" |
| ejteb | 0:6aa04a8c8d4c | 5 | |
| ejteb | 0:6aa04a8c8d4c | 6 | class ultrasonic |
| ejteb | 0:6aa04a8c8d4c | 7 | { |
| ejteb | 0:6aa04a8c8d4c | 8 | public: |
| ejteb | 2:cc1143d36567 | 9 | /**iniates the class with the specified trigger pin, echo pin, update speed and timeout**/ |
| ejteb | 0:6aa04a8c8d4c | 10 | ultrasonic(PinName trigPin, PinName echoPin, float updateSpeed, float timeout); |
| ejteb | 2:cc1143d36567 | 11 | /**iniates the class with the specified trigger pin, echo pin, update speed, timeout and method to call when the distance changes**/ |
| ejteb | 2:cc1143d36567 | 12 | ultrasonic(PinName trigPin, PinName echoPin, float updateSpeed, float timeout, void onUpdate(int)); |
| ejteb | 2:cc1143d36567 | 13 | /** returns the last measured distance**/ |
| ejteb | 0:6aa04a8c8d4c | 14 | int getCurrentDistance(void); |
| ejteb | 2:cc1143d36567 | 15 | /**pauses measuring the distance**/ |
| ejteb | 0:6aa04a8c8d4c | 16 | void pauseUpdates(void); |
| ejteb | 2:cc1143d36567 | 17 | /**starts mesuring the distance**/ |
| ejteb | 0:6aa04a8c8d4c | 18 | void startUpdates(void); |
| ejteb | 2:cc1143d36567 | 19 | /**attachs the method to be called when the distances changes**/ |
| ejteb | 0:6aa04a8c8d4c | 20 | void attachOnUpdate(void method(int)); |
| ejteb | 2:cc1143d36567 | 21 | /**changes the speed at which updates are made**/ |
| ejteb | 0:6aa04a8c8d4c | 22 | void changeUpdateSpeed(float updateSpeed); |
| ejteb | 2:cc1143d36567 | 23 | /**gets whether the distance has been changed since the last call of isUpdated() or checkDistance()**/ |
| ejteb | 0:6aa04a8c8d4c | 24 | int isUpdated(void); |
| ejteb | 2:cc1143d36567 | 25 | /**gets the speed at which updates are made**/ |
| ejteb | 2:cc1143d36567 | 26 | float getUpdateSpeed(void); |
| ejteb | 2:cc1143d36567 | 27 | /**call this as often as possible in your code, eg. at the end of a while(1) loop, |
| ejteb | 2:cc1143d36567 | 28 | and it will check whether the method you have attached needs to be called**/ |
| ejteb | 2:cc1143d36567 | 29 | void checkDistance(void); |
| ejteb | 0:6aa04a8c8d4c | 30 | private: |
| ejteb | 0:6aa04a8c8d4c | 31 | DigitalOut _trig; |
| ejteb | 0:6aa04a8c8d4c | 32 | InterruptIn _echo; |
| ejteb | 0:6aa04a8c8d4c | 33 | Timer _t; |
| ejteb | 0:6aa04a8c8d4c | 34 | Timeout _tout; |
| ejteb | 0:6aa04a8c8d4c | 35 | int _distance; |
| ejteb | 0:6aa04a8c8d4c | 36 | float _updateSpeed; |
| ejteb | 0:6aa04a8c8d4c | 37 | int start; |
| ejteb | 0:6aa04a8c8d4c | 38 | int end; |
| ejteb | 0:6aa04a8c8d4c | 39 | volatile int done; |
| ejteb | 0:6aa04a8c8d4c | 40 | void (*_onUpdateMethod)(int); |
| ejteb | 0:6aa04a8c8d4c | 41 | void _startT(void); |
| ejteb | 0:6aa04a8c8d4c | 42 | void _updateDist(void); |
| ejteb | 0:6aa04a8c8d4c | 43 | void _startTrig(void); |
| ejteb | 0:6aa04a8c8d4c | 44 | float _timeout; |
| ejteb | 0:6aa04a8c8d4c | 45 | int d; |
| ejteb | 0:6aa04a8c8d4c | 46 | }; |
| ejteb | 0:6aa04a8c8d4c | 47 | #endif |
