
Final Project로 실제 점검에 사용된 코드
Dependencies: mbed Adafruit_GFX
Diff: Ultrasonic.h
- Revision:
- 0:22391cd705e2
diff -r 000000000000 -r 22391cd705e2 Ultrasonic.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Ultrasonic.h Sat Jun 15 20:52:15 2019 +0000 @@ -0,0 +1,40 @@ +#ifndef MBED_ULTRASONIC_H +#define MBED_ULTRASONIC_H + +#include "mbed.h" + +class Ultrasonic +{ +public: + Ultrasonic(PinName trigPin, PinName echoPin, float tick = 0.1, bool repeat = false); + ~Ultrasonic(); + + void trig(); + int getDistance(void); + int getPulseDuration(void); + + //the ultrasonic sensor will stop after measuring once, use clear to clear the value + int getStatus(void); + void clearStatus(void); + + void pauseMeasure(void); + void setMode(bool mode); +private: + DigitalOut _trig; + InterruptIn _echo; + + Timer _timer; + Ticker _ticker; + float _toVal; + bool _repeat; + + int _distance; + int _pulseDuration; + + void _startT(void); + void _endT(void); + void _ticker_cb(void); + int _done; +}; + +#endif MBED_ULTRASONIC_H \ No newline at end of file