나중에 급하게 PID 알고리즘을 적용해 짜본 코드... 시간이 충분치 않아서 그냥 원래 있던 코드를 수정해서 하기로 했기에 버려진 코드지만, 교수님께 참고용으로 Publish를 했다.
Dependencies: mbed Adafruit_GFX
Diff: Ultrasonic.h
- Revision:
- 0:c4c874d702f9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Ultrasonic.h Sat Jun 15 20:39:39 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