Fork of encoder2 by
Diff: encoder2.cpp
- Revision:
- 2:82a12d9f0bca
- Child:
- 3:03bca13f0bf6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/encoder2.cpp Tue Mar 27 03:45:26 2018 +0000 @@ -0,0 +1,38 @@ +#include "encoder2.h" +#include "mbed.h" + +Encoder2::Encoder2(PinName APin, PinName BPin, PinName ZPin) : A(APin) , B(BPin) , Z(ZPin){ + A.rise(this,&Encoder2::flag); + init(); +} + +void Encoder2::init(void){ + count = 0; + zcount = 0; +} + +void Encoder2::flag(void){ + if(B == true){ + count++; + if(Z == true){ + zcount++; + count=0; + } + }else{ + count--; + if(Z == true){ + zcount--; + count=0; + } + } +} + +int Encoder2::read_rotate(){ + return count; +} + +int Encoder2::read_z(){ + return zcount; +} + +