齋藤、玉田要

Dependencies:   mbed AQM0802 CRotaryEncoder TB6612FNG

main.cpp

Committer:
yusaku0125
Date:
2019-07-22
Revision:
0:df99e50ed3fd
Child:
1:19e2241a7aa7

File content as of revision 0:df99e50ed3fd:

 //エンコーダの動作確認。
 //左右モータの回転数を検出するプログラム
 #include "mbed.h"
 #include "CRotaryEncoder.h"
 
 Serial PC(USBTX,USBRX);
 CRotaryEncoder encoder_a(D1,D0);       //モータAのエンコーダ
 CRotaryEncoder encoder_b(D11,D12);     //モータBのエンコーダ
  
 
 int main(){
    int enc_count_a=0,enc_count_b=0;    //エンコーダパルス数を格納
    int rotation_a=0,rotation_b=0;      //回転数を格納
     while(1)
    {
         enc_count_a=encoder_a.Get();   //エンコーダパルス数を取得
         enc_count_b=encoder_b.Get();
         rotation_a=enc_count_a/400;    //400パルスで一回転
         rotation_b=enc_count_b/400;    
         PC.printf("enc_a:%d   enc_b:%d\r\n",rotation_a,rotation_b);//表示
         wait(0.5);
    }
 }