ちょっとかえた
Fork of encoder by
encoder.cpp
- Committer:
- frute8
- Date:
- 2018-03-26
- Revision:
- 1:6456080fa03b
- Parent:
- 0:0d6f91c4a794
File content as of revision 1:6456080fa03b:
#include "encoder.h" #include "mbed.h" Encoder::Encoder(PinName APin, PinName BPin, PinName ZPin) : A(APin) , B(BPin) , Z(ZPin){ A.rise(this,&Encoder::flag); init(); } void Encoder::init(void){ count = 0; zcount = 0; } void Encoder::flag(void){ if(B == true){ count++; if(Z == true){ zcount++; count=0; } }else{ count--; if(Z == true){ zcount--; count=0; } } } int Encoder::read_rotate(){ return count; } int Encoder::read_z(){ return zcount; }