最終調整
Dependencies: mbed AQM0802 CRotaryEncoder TB6612FNG
main.cpp@0:df99e50ed3fd, 2019-07-22 (annotated)
- Committer:
- yusaku0125
- Date:
- Mon Jul 22 04:03:37 2019 +0000
- Revision:
- 0:df99e50ed3fd
- Child:
- 1:19e2241a7aa7
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yusaku0125 | 0:df99e50ed3fd | 1 | //エンコーダの動作確認。 |
yusaku0125 | 0:df99e50ed3fd | 2 | //左右モータの回転数を検出するプログラム |
yusaku0125 | 0:df99e50ed3fd | 3 | #include "mbed.h" |
yusaku0125 | 0:df99e50ed3fd | 4 | #include "CRotaryEncoder.h" |
yusaku0125 | 0:df99e50ed3fd | 5 | |
yusaku0125 | 0:df99e50ed3fd | 6 | Serial PC(USBTX,USBRX); |
yusaku0125 | 0:df99e50ed3fd | 7 | CRotaryEncoder encoder_a(D1,D0); //モータAのエンコーダ |
yusaku0125 | 0:df99e50ed3fd | 8 | CRotaryEncoder encoder_b(D11,D12); //モータBのエンコーダ |
yusaku0125 | 0:df99e50ed3fd | 9 | |
yusaku0125 | 0:df99e50ed3fd | 10 | |
yusaku0125 | 0:df99e50ed3fd | 11 | int main(){ |
yusaku0125 | 0:df99e50ed3fd | 12 | int enc_count_a=0,enc_count_b=0; //エンコーダパルス数を格納 |
yusaku0125 | 0:df99e50ed3fd | 13 | int rotation_a=0,rotation_b=0; //回転数を格納 |
yusaku0125 | 0:df99e50ed3fd | 14 | while(1) |
yusaku0125 | 0:df99e50ed3fd | 15 | { |
yusaku0125 | 0:df99e50ed3fd | 16 | enc_count_a=encoder_a.Get(); //エンコーダパルス数を取得 |
yusaku0125 | 0:df99e50ed3fd | 17 | enc_count_b=encoder_b.Get(); |
yusaku0125 | 0:df99e50ed3fd | 18 | rotation_a=enc_count_a/400; //400パルスで一回転 |
yusaku0125 | 0:df99e50ed3fd | 19 | rotation_b=enc_count_b/400; |
yusaku0125 | 0:df99e50ed3fd | 20 | PC.printf("enc_a:%d enc_b:%d\r\n",rotation_a,rotation_b);//表示 |
yusaku0125 | 0:df99e50ed3fd | 21 | wait(0.5); |
yusaku0125 | 0:df99e50ed3fd | 22 | } |
yusaku0125 | 0:df99e50ed3fd | 23 | } |