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@1:114e0698a5d2, 2014-11-23 (annotated)
- Committer:
- ejteb
- Date:
- Sun Nov 23 20:34:26 2014 +0000
- Revision:
- 1:114e0698a5d2
- Parent:
- 0:6aa04a8c8d4c
- Child:
- 2:cc1143d36567
Ultrasonic with interrupts
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 | 1:114e0698a5d2 | 9 | |
| ejteb | 0:6aa04a8c8d4c | 10 | ultrasonic(PinName trigPin, PinName echoPin, float updateSpeed, float timeout); |
| ejteb | 0:6aa04a8c8d4c | 11 | ultrasonic(PinName trigPin, PinName echoPin, float updateSpeed, float timeout, void onUpdate(int), void onTrig(void),void onStartTimer(void)/*, Timer *t*/ ); |
| ejteb | 0:6aa04a8c8d4c | 12 | int getCurrentDistance(void); |
| ejteb | 0:6aa04a8c8d4c | 13 | void pauseUpdates(void); |
| ejteb | 0:6aa04a8c8d4c | 14 | void startUpdates(void); |
| ejteb | 0:6aa04a8c8d4c | 15 | void attachOnUpdate(void method(int)); |
| ejteb | 0:6aa04a8c8d4c | 16 | void attachOnTrigger(void method(void)); |
| ejteb | 0:6aa04a8c8d4c | 17 | void attachOnStartTimer(void method(void)); |
| ejteb | 0:6aa04a8c8d4c | 18 | void changeUpdateSpeed(float updateSpeed); |
| ejteb | 0:6aa04a8c8d4c | 19 | int isUpdated(void); |
| ejteb | 0:6aa04a8c8d4c | 20 | float getUpdateSpeed(); |
| ejteb | 0:6aa04a8c8d4c | 21 | private: |
| ejteb | 0:6aa04a8c8d4c | 22 | DigitalOut _trig; |
| ejteb | 0:6aa04a8c8d4c | 23 | InterruptIn _echo; |
| ejteb | 0:6aa04a8c8d4c | 24 | Timer _t; |
| ejteb | 0:6aa04a8c8d4c | 25 | Timeout _tout; |
| ejteb | 0:6aa04a8c8d4c | 26 | int _distance; |
| ejteb | 0:6aa04a8c8d4c | 27 | float _updateSpeed; |
| ejteb | 0:6aa04a8c8d4c | 28 | int start; |
| ejteb | 0:6aa04a8c8d4c | 29 | int end; |
| ejteb | 0:6aa04a8c8d4c | 30 | volatile int done; |
| ejteb | 0:6aa04a8c8d4c | 31 | void (*_onUpdateMethod)(int); |
| ejteb | 0:6aa04a8c8d4c | 32 | void (*_onTriggerMethod)(void); |
| ejteb | 0:6aa04a8c8d4c | 33 | void (*_onStartTimerMethod)(void); |
| ejteb | 0:6aa04a8c8d4c | 34 | void _startT(void); |
| ejteb | 0:6aa04a8c8d4c | 35 | void _updateDist(void); |
| ejteb | 0:6aa04a8c8d4c | 36 | void _startTrig(void); |
| ejteb | 0:6aa04a8c8d4c | 37 | float _timeout; |
| ejteb | 0:6aa04a8c8d4c | 38 | |
| ejteb | 0:6aa04a8c8d4c | 39 | int d; |
| ejteb | 0:6aa04a8c8d4c | 40 | /*unsigned int tickcount; |
| ejteb | 0:6aa04a8c8d4c | 41 | Ticker _ticker; |
| ejteb | 0:6aa04a8c8d4c | 42 | void ticktock(void);*/ |
| ejteb | 0:6aa04a8c8d4c | 43 | }; |
| ejteb | 0:6aa04a8c8d4c | 44 | #endif |
