超音波センサーのプログラムです。
Dependencies: mbed
us015.h@0:84736ef4c7d4, 2021-10-20 (annotated)
- Committer:
- ushiroji
- Date:
- Wed Oct 20 07:02:30 2021 +0000
- Revision:
- 0:84736ef4c7d4
test;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ushiroji | 0:84736ef4c7d4 | 1 | #ifndef __US015_H |
ushiroji | 0:84736ef4c7d4 | 2 | #define __US015_H |
ushiroji | 0:84736ef4c7d4 | 3 | |
ushiroji | 0:84736ef4c7d4 | 4 | #include "mbed.h" |
ushiroji | 0:84736ef4c7d4 | 5 | |
ushiroji | 0:84736ef4c7d4 | 6 | |
ushiroji | 0:84736ef4c7d4 | 7 | //==================================== |
ushiroji | 0:84736ef4c7d4 | 8 | // define定義 |
ushiroji | 0:84736ef4c7d4 | 9 | //==================================== |
ushiroji | 0:84736ef4c7d4 | 10 | #define US015_TRIGER_ON 1 // トリガーON |
ushiroji | 0:84736ef4c7d4 | 11 | #define US015_TRIGER_OFF 0 // トリガーOFF |
ushiroji | 0:84736ef4c7d4 | 12 | #define US015_TRIGER_PALUSE_WIDTH 10 // トリガーの幅 |
ushiroji | 0:84736ef4c7d4 | 13 | #define US015_PERIODIC_TRIGER 100000 // 音響測距トリガー |
ushiroji | 0:84736ef4c7d4 | 14 | #define US015_SOUND_OF_SPEED 0.340 // 音速[mm/us] |
ushiroji | 0:84736ef4c7d4 | 15 | |
ushiroji | 0:84736ef4c7d4 | 16 | |
ushiroji | 0:84736ef4c7d4 | 17 | //==================================== |
ushiroji | 0:84736ef4c7d4 | 18 | // 音響測距センサ(US015)の制御クラス |
ushiroji | 0:84736ef4c7d4 | 19 | //==================================== |
ushiroji | 0:84736ef4c7d4 | 20 | class US015 |
ushiroji | 0:84736ef4c7d4 | 21 | { |
ushiroji | 0:84736ef4c7d4 | 22 | public: |
ushiroji | 0:84736ef4c7d4 | 23 | US015(PinName trg, PinName ech); |
ushiroji | 0:84736ef4c7d4 | 24 | US015(PinName trg, PinName ech, float tkTime); |
ushiroji | 0:84736ef4c7d4 | 25 | float GetDistance(); |
ushiroji | 0:84736ef4c7d4 | 26 | void TrigerOut(); // トリガー出力 |
ushiroji | 0:84736ef4c7d4 | 27 | |
ushiroji | 0:84736ef4c7d4 | 28 | private: |
ushiroji | 0:84736ef4c7d4 | 29 | DigitalOut _trigerOut; // U015トリガー出力 |
ushiroji | 0:84736ef4c7d4 | 30 | InterruptIn _interruptEcho; // U015エコー入力 |
ushiroji | 0:84736ef4c7d4 | 31 | Timer timer; // 時間計測用のタイマ |
ushiroji | 0:84736ef4c7d4 | 32 | Ticker tk; // 周期処理用のチッカー |
ushiroji | 0:84736ef4c7d4 | 33 | float tmBegin; // エコーの立ち上がり時間 |
ushiroji | 0:84736ef4c7d4 | 34 | float tmEnd; // エコーの立ち下がり時間 |
ushiroji | 0:84736ef4c7d4 | 35 | float distance; // 距離測定 |
ushiroji | 0:84736ef4c7d4 | 36 | void EchoFall(); // エコーの立ち下がり処理 |
ushiroji | 0:84736ef4c7d4 | 37 | void EchoRise(); // エコーの立ち上がり処理 |
ushiroji | 0:84736ef4c7d4 | 38 | }; |
ushiroji | 0:84736ef4c7d4 | 39 | |
ushiroji | 0:84736ef4c7d4 | 40 | #endif |