Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed CRotaryEncoder
main.cpp
- Committer:
- yusaku0125
- Date:
- 2019-07-22
- Revision:
- 0:df99e50ed3fd
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);
}
}