割り込みを利用して超音波測距センサーをバックグラウンドで計測し続けられます。
Dependents: escapeFromYou Sample_LinetraceWithSonicDist
SonicDist.h@8:8bb311d39a99, 2017-03-02 (annotated)
- Committer:
- natuga117
- Date:
- Thu Mar 02 18:01:45 2017 +0000
- Revision:
- 8:8bb311d39a99
- Parent:
- 6:ba801e0b68df
improved precision
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
natuga117 | 0:987c196d3023 | 1 | #ifndef SOCKET_MODULE_H |
natuga117 | 0:987c196d3023 | 2 | #define SOCKET_MODULE_H |
natuga117 | 0:987c196d3023 | 3 | #include "mbed.h" |
natuga117 | 0:987c196d3023 | 4 | |
natuga117 | 0:987c196d3023 | 5 | #ifndef DIST_S |
natuga117 | 0:987c196d3023 | 6 | #define DIST_S |
natuga117 | 0:987c196d3023 | 7 | class SonicDist |
natuga117 | 0:987c196d3023 | 8 | { |
natuga117 | 0:987c196d3023 | 9 | public: |
natuga117 | 0:987c196d3023 | 10 | SonicDist(PinName Trig, PinName Echo); |
natuga117 | 4:84f4fa630726 | 11 | double read(void); |
natuga117 | 4:84f4fa630726 | 12 | double read_mm(void); |
natuga117 | 6:ba801e0b68df | 13 | double takeDist(void); |
natuga117 | 8:8bb311d39a99 | 14 | void Init(void); |
natuga117 | 0:987c196d3023 | 15 | private: |
natuga117 | 0:987c196d3023 | 16 | void releaseTrig(void); |
natuga117 | 0:987c196d3023 | 17 | void setTrig(void); |
natuga117 | 0:987c196d3023 | 18 | void endMeasure(void); |
natuga117 | 8:8bb311d39a99 | 19 | void FallNoiseCheck(void);//立ち下がりノイズの判定 |
natuga117 | 0:987c196d3023 | 20 | void StartMeasure(void); |
natuga117 | 6:ba801e0b68df | 21 | double soundspeed;//音速 |
natuga117 | 0:987c196d3023 | 22 | bool startflag; |
natuga117 | 6:ba801e0b68df | 23 | Ticker pulse; |
natuga117 | 8:8bb311d39a99 | 24 | Timeout Postponement;//ノイズ判定を行うための割り込み |
natuga117 | 0:987c196d3023 | 25 | DigitalOut* trig; |
natuga117 | 0:987c196d3023 | 26 | InterruptIn* echo; |
natuga117 | 0:987c196d3023 | 27 | Timer echotime; |
natuga117 | 8:8bb311d39a99 | 28 | int distbuf;//仮格納距離(mm) |
natuga117 | 8:8bb311d39a99 | 29 | bool NoiseCheckFlag;//ノイズチェックが終了しているかの判定用 |
natuga117 | 0:987c196d3023 | 30 | int dist;//距離(mm) |
natuga117 | 0:987c196d3023 | 31 | }; |
natuga117 | 0:987c196d3023 | 32 | #endif |
natuga117 | 0:987c196d3023 | 33 | |
natuga117 | 0:987c196d3023 | 34 | #endif |