나중에 급하게 PID 알고리즘을 적용해 짜본 코드... 시간이 충분치 않아서 그냥 원래 있던 코드를 수정해서 하기로 했기에 버려진 코드지만, 교수님께 참고용으로 Publish를 했다.
Dependencies: mbed Adafruit_GFX
Ultrasonic.h@0:c4c874d702f9, 2019-06-15 (annotated)
- Committer:
- 21400688
- Date:
- Sat Jun 15 20:39:39 2019 +0000
- Revision:
- 0:c4c874d702f9
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
21400688 | 0:c4c874d702f9 | 1 | #ifndef MBED_ULTRASONIC_H |
21400688 | 0:c4c874d702f9 | 2 | #define MBED_ULTRASONIC_H |
21400688 | 0:c4c874d702f9 | 3 | |
21400688 | 0:c4c874d702f9 | 4 | #include "mbed.h" |
21400688 | 0:c4c874d702f9 | 5 | |
21400688 | 0:c4c874d702f9 | 6 | class Ultrasonic |
21400688 | 0:c4c874d702f9 | 7 | { |
21400688 | 0:c4c874d702f9 | 8 | public: |
21400688 | 0:c4c874d702f9 | 9 | Ultrasonic(PinName trigPin, PinName echoPin, float tick = 0.1, bool repeat = false); |
21400688 | 0:c4c874d702f9 | 10 | ~Ultrasonic(); |
21400688 | 0:c4c874d702f9 | 11 | |
21400688 | 0:c4c874d702f9 | 12 | void trig(); |
21400688 | 0:c4c874d702f9 | 13 | int getDistance(void); |
21400688 | 0:c4c874d702f9 | 14 | int getPulseDuration(void); |
21400688 | 0:c4c874d702f9 | 15 | |
21400688 | 0:c4c874d702f9 | 16 | //the ultrasonic sensor will stop after measuring once, use clear to clear the value |
21400688 | 0:c4c874d702f9 | 17 | int getStatus(void); |
21400688 | 0:c4c874d702f9 | 18 | void clearStatus(void); |
21400688 | 0:c4c874d702f9 | 19 | |
21400688 | 0:c4c874d702f9 | 20 | void pauseMeasure(void); |
21400688 | 0:c4c874d702f9 | 21 | void setMode(bool mode); |
21400688 | 0:c4c874d702f9 | 22 | private: |
21400688 | 0:c4c874d702f9 | 23 | DigitalOut _trig; |
21400688 | 0:c4c874d702f9 | 24 | InterruptIn _echo; |
21400688 | 0:c4c874d702f9 | 25 | |
21400688 | 0:c4c874d702f9 | 26 | Timer _timer; |
21400688 | 0:c4c874d702f9 | 27 | Ticker _ticker; |
21400688 | 0:c4c874d702f9 | 28 | float _toVal; |
21400688 | 0:c4c874d702f9 | 29 | bool _repeat; |
21400688 | 0:c4c874d702f9 | 30 | |
21400688 | 0:c4c874d702f9 | 31 | int _distance; |
21400688 | 0:c4c874d702f9 | 32 | int _pulseDuration; |
21400688 | 0:c4c874d702f9 | 33 | |
21400688 | 0:c4c874d702f9 | 34 | void _startT(void); |
21400688 | 0:c4c874d702f9 | 35 | void _endT(void); |
21400688 | 0:c4c874d702f9 | 36 | void _ticker_cb(void); |
21400688 | 0:c4c874d702f9 | 37 | int _done; |
21400688 | 0:c4c874d702f9 | 38 | }; |
21400688 | 0:c4c874d702f9 | 39 | |
21400688 | 0:c4c874d702f9 | 40 | #endif MBED_ULTRASONIC_H |