aa
Diff: Ultrasonic.h
- Revision:
- 0:6269b1b47590
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Ultrasonic.h Wed Jun 12 13:21:41 2019 +0000 @@ -0,0 +1,39 @@ +#ifndef MBED_ULTRASONIC_H +#define MBED_ULTRASONIC_H + +#include "mbed.h" +/*header file Ultrasonic module HC-SR04*/ +class Ultrasonic { + public: + Ultrasonic(PinName trigPin, PinName echoPin, float tick = 0.1, bool repeat = false); + ~Ultrasonic(); + + void trig(); + int getDistance(void); + int getPulseDuration(void); + int getStatus(void); + + void clearStatus(void); + void pauseMeasure(void); + void setMode(bool mode); + + void setTick(float tick); + private: + DigitalOut _trig; + InterruptIn _echo; + Timer _timer; + Ticker _ticker; + + float _toVal; + bool _repeat; + int _done; + + int _distance; + int _pulseDuration; + + void _startT(void); + void _endT(void); + void _ticker_cb(void); +}; + +#endif MBED_ULTRASONIC_H \ No newline at end of file