Sonar
Diff: angledSonar.h
- Revision:
- 0:932004bfb013
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/angledSonar.h Wed Jun 13 09:22:37 2018 +0000 @@ -0,0 +1,36 @@ +#include "mbed.h" + +struct Point{ + float x; + float y; +}; + +class Sonar{ + public: + Sonar(PinName trig, PinName echo, float angle_z = 0, float x = 0, float y = 0, float z = 0); + float getDistance(); + float getLastDistance() {return _distance;} + Point getCoordinate(); + void autoPulse(bool on_off, float frequency_ms = 1); + void pulse(); + + private: + Ticker _ticker; + Timer _timer; + DigitalOut _trig; + InterruptIn _echo; + + int _begin; + int _end; + float _distance; + bool _pinged; + + float _ratio_x; + float _ratio_y; + float _x; + float _y; + float _z; + + void echoBegin(); + void echoEnd(); +}; \ No newline at end of file