インクリメント方式エンコーダ用ライブラリ

Dependents:   RobotControl_Sample2022 sotsuken_mecha

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IncEncoder.cpp Source File

IncEncoder.cpp

00001 #include "IncEncoder.h"
00002 #include "mbed.h"
00003 
00004 IncEncoder::IncEncoder(PinName ENC_A,PinName ENC_B,Encoding encoding) : ENC_A_(ENC_A),ENC_B_(ENC_B){
00005     pulses = 0;
00006     
00007     ENC_A_.rise(this, &IncEncoder::A_RISE);
00008     ENC_A_.fall(this, &IncEncoder::A_FALL);
00009     
00010     if(encoding == x4_Resolution){
00011         ENC_B_.rise(this, &IncEncoder::B_RISE);
00012         ENC_B_.fall(this, &IncEncoder::B_FALL);
00013     }
00014 }
00015 
00016 int IncEncoder::GetIncPulses(){
00017     return pulses;
00018 }
00019 
00020 void IncEncoder::reset(){
00021     pulses = 0;
00022 }
00023 
00024 void IncEncoder::A_RISE(){
00025     if(ENC_B_) pulses++;
00026     else       pulses--;
00027 }
00028 
00029 void IncEncoder::A_FALL(){
00030     if(ENC_B_) pulses--;
00031     else       pulses++;
00032 }
00033 
00034 void IncEncoder::B_RISE(){
00035     if(ENC_A_) pulses--;
00036     else       pulses++;
00037 }
00038 
00039 void IncEncoder::B_FALL(){
00040     if(ENC_A_) pulses++;
00041     else       pulses--;
00042 }