seisaku

Dependencies:   mbed QEI

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //-------------------------------------------------------------------
00002 //QEIライブラリ使用
00003 //-------------------------------------------------------------------
00004 
00005 //mbed用ライブラリ
00006 #include "mbed.h"
00007 //エンコーダ用ライブラリ
00008 #include "QEI.h"
00009 
00010 //変数宣言
00011 //1回転でのパルス数
00012 #define ROTATE_PER_REVOLUTIONS  360
00013 
00014 //エンコーダのチャンネルAとBの初期状態を決める
00015 QEI wheel(P1_0, P1_1, NC, ROTATE_PER_REVOLUTIONS, QEI::X4_ENCODING);
00016 
00017 //メイン関数
00018 int main()
00019 {
00020     //作業用変数
00021     long delt_ms = 1;
00022     wait_ms(delt_ms);
00023 
00024     while(1) {
00025         
00026         //エンコーダ値格納用変数
00027         static double y;
00028         static double x;
00029         
00030         //エンコーダの値(生)の取得
00031         y=(double)wheel.getPulses();
00032         
00033         //エンコーダの値を角度に変換
00034         x=y*360/(ROTATE_PER_REVOLUTIONS);
00035         
00036         //エンコーダ値(角度)の表示(TeraTerm)
00037         printf("%f\r\n",x);
00038         
00039         //待機時間(1ミリ秒)
00040         wait_ms(delt_ms);
00041 
00042     }
00043 
00044 }