齋藤、玉田要

Dependencies:   mbed AQM0802 CRotaryEncoder TB6612FNG

Revision:
0:df99e50ed3fd
Child:
1:19e2241a7aa7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 22 04:03:37 2019 +0000
@@ -0,0 +1,23 @@
+ //エンコーダの動作確認。
+ //左右モータの回転数を検出するプログラム
+ #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);
+    }
+ }