aa
Ultrasonic.h@0:6269b1b47590, 2019-06-12 (annotated)
- Committer:
- taeyeobyeo
- Date:
- Wed Jun 12 13:21:41 2019 +0000
- Revision:
- 0:6269b1b47590
aa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
taeyeobyeo | 0:6269b1b47590 | 1 | #ifndef MBED_ULTRASONIC_H |
taeyeobyeo | 0:6269b1b47590 | 2 | #define MBED_ULTRASONIC_H |
taeyeobyeo | 0:6269b1b47590 | 3 | |
taeyeobyeo | 0:6269b1b47590 | 4 | #include "mbed.h" |
taeyeobyeo | 0:6269b1b47590 | 5 | /*header file Ultrasonic module HC-SR04*/ |
taeyeobyeo | 0:6269b1b47590 | 6 | class Ultrasonic { |
taeyeobyeo | 0:6269b1b47590 | 7 | public: |
taeyeobyeo | 0:6269b1b47590 | 8 | Ultrasonic(PinName trigPin, PinName echoPin, float tick = 0.1, bool repeat = false); |
taeyeobyeo | 0:6269b1b47590 | 9 | ~Ultrasonic(); |
taeyeobyeo | 0:6269b1b47590 | 10 | |
taeyeobyeo | 0:6269b1b47590 | 11 | void trig(); |
taeyeobyeo | 0:6269b1b47590 | 12 | int getDistance(void); |
taeyeobyeo | 0:6269b1b47590 | 13 | int getPulseDuration(void); |
taeyeobyeo | 0:6269b1b47590 | 14 | int getStatus(void); |
taeyeobyeo | 0:6269b1b47590 | 15 | |
taeyeobyeo | 0:6269b1b47590 | 16 | void clearStatus(void); |
taeyeobyeo | 0:6269b1b47590 | 17 | void pauseMeasure(void); |
taeyeobyeo | 0:6269b1b47590 | 18 | void setMode(bool mode); |
taeyeobyeo | 0:6269b1b47590 | 19 | |
taeyeobyeo | 0:6269b1b47590 | 20 | void setTick(float tick); |
taeyeobyeo | 0:6269b1b47590 | 21 | private: |
taeyeobyeo | 0:6269b1b47590 | 22 | DigitalOut _trig; |
taeyeobyeo | 0:6269b1b47590 | 23 | InterruptIn _echo; |
taeyeobyeo | 0:6269b1b47590 | 24 | Timer _timer; |
taeyeobyeo | 0:6269b1b47590 | 25 | Ticker _ticker; |
taeyeobyeo | 0:6269b1b47590 | 26 | |
taeyeobyeo | 0:6269b1b47590 | 27 | float _toVal; |
taeyeobyeo | 0:6269b1b47590 | 28 | bool _repeat; |
taeyeobyeo | 0:6269b1b47590 | 29 | int _done; |
taeyeobyeo | 0:6269b1b47590 | 30 | |
taeyeobyeo | 0:6269b1b47590 | 31 | int _distance; |
taeyeobyeo | 0:6269b1b47590 | 32 | int _pulseDuration; |
taeyeobyeo | 0:6269b1b47590 | 33 | |
taeyeobyeo | 0:6269b1b47590 | 34 | void _startT(void); |
taeyeobyeo | 0:6269b1b47590 | 35 | void _endT(void); |
taeyeobyeo | 0:6269b1b47590 | 36 | void _ticker_cb(void); |
taeyeobyeo | 0:6269b1b47590 | 37 | }; |
taeyeobyeo | 0:6269b1b47590 | 38 | |
taeyeobyeo | 0:6269b1b47590 | 39 | #endif MBED_ULTRASONIC_H |