ちょっとかえた
Fork of encoder by
Diff: encoder.cpp
- Revision:
- 2:82a12d9f0bca
- Parent:
- 1:6456080fa03b
diff -r 6456080fa03b -r 82a12d9f0bca encoder.cpp --- a/encoder.cpp Mon Mar 26 20:42:49 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -#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; -} - -