(多分)全部+フライトピン+新しい加速度
Dependencies: mbed
ultrasonic.h@40:d0b0d2a26cac, 2018-12-16 (annotated)
- Committer:
- seangshim
- Date:
- Sun Dec 16 02:11:48 2018 +0000
- Revision:
- 40:d0b0d2a26cac
- Parent:
- 0:a01fda36fde8
new
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
seangshim | 0:a01fda36fde8 | 1 | #ifndef MBED_ULTRASONIC_H |
seangshim | 0:a01fda36fde8 | 2 | #define MBED_ULTRASONIC_H |
seangshim | 0:a01fda36fde8 | 3 | |
seangshim | 0:a01fda36fde8 | 4 | #include "mbed.h" |
seangshim | 0:a01fda36fde8 | 5 | |
seangshim | 0:a01fda36fde8 | 6 | class ultrasonic |
seangshim | 0:a01fda36fde8 | 7 | { |
seangshim | 0:a01fda36fde8 | 8 | public: |
seangshim | 0:a01fda36fde8 | 9 | /**iniates the class with the specified trigger pin, echo pin, update speed and timeout**/ |
seangshim | 0:a01fda36fde8 | 10 | ultrasonic(PinName trigPin, PinName echoPin, float updateSpeed, float timeout); |
seangshim | 0:a01fda36fde8 | 11 | /**iniates the class with the specified trigger pin, echo pin, update speed, timeout and method to call when the distance changes**/ |
seangshim | 0:a01fda36fde8 | 12 | ultrasonic(PinName trigPin, PinName echoPin, float updateSpeed, float timeout, void onUpdate(int)); |
seangshim | 0:a01fda36fde8 | 13 | /** returns the last measured distance**/ |
seangshim | 0:a01fda36fde8 | 14 | int getCurrentDistance(void); |
seangshim | 0:a01fda36fde8 | 15 | /**pauses measuring the distance**/ |
seangshim | 0:a01fda36fde8 | 16 | void pauseUpdates(void); |
seangshim | 0:a01fda36fde8 | 17 | /**starts mesuring the distance**/ |
seangshim | 0:a01fda36fde8 | 18 | void startUpdates(void); |
seangshim | 0:a01fda36fde8 | 19 | /**attachs the method to be called when the distances changes**/ |
seangshim | 0:a01fda36fde8 | 20 | void attachOnUpdate(void method(int)); |
seangshim | 0:a01fda36fde8 | 21 | /**changes the speed at which updates are made**/ |
seangshim | 0:a01fda36fde8 | 22 | void changeUpdateSpeed(float updateSpeed); |
seangshim | 0:a01fda36fde8 | 23 | /**gets whether the distance has been changed since the last call of isUpdated() or checkDistance()**/ |
seangshim | 0:a01fda36fde8 | 24 | int isUpdated(void); |
seangshim | 0:a01fda36fde8 | 25 | /**gets the speed at which updates are made**/ |
seangshim | 0:a01fda36fde8 | 26 | float getUpdateSpeed(void); |
seangshim | 0:a01fda36fde8 | 27 | /**call this as often as possible in your code, eg. at the end of a while(1) loop, |
seangshim | 0:a01fda36fde8 | 28 | and it will check whether the method you have attached needs to be called**/ |
seangshim | 0:a01fda36fde8 | 29 | void checkDistance(void); |
seangshim | 0:a01fda36fde8 | 30 | private: |
seangshim | 0:a01fda36fde8 | 31 | DigitalOut _trig; |
seangshim | 0:a01fda36fde8 | 32 | InterruptIn _echo; |
seangshim | 0:a01fda36fde8 | 33 | Timer _t; |
seangshim | 0:a01fda36fde8 | 34 | Timeout _tout; |
seangshim | 0:a01fda36fde8 | 35 | int _distance; |
seangshim | 0:a01fda36fde8 | 36 | float _updateSpeed; |
seangshim | 0:a01fda36fde8 | 37 | int start; |
seangshim | 0:a01fda36fde8 | 38 | int end; |
seangshim | 0:a01fda36fde8 | 39 | volatile int done; |
seangshim | 0:a01fda36fde8 | 40 | void (*_onUpdateMethod)(int); |
seangshim | 0:a01fda36fde8 | 41 | void _startT(void); |
seangshim | 0:a01fda36fde8 | 42 | void _updateDist(void); |
seangshim | 0:a01fda36fde8 | 43 | void _startTrig(void); |
seangshim | 0:a01fda36fde8 | 44 | float _timeout; |
seangshim | 0:a01fda36fde8 | 45 | int d; |
seangshim | 0:a01fda36fde8 | 46 | }; |
seangshim | 0:a01fda36fde8 | 47 | #endif |