ちょっとかえた
Fork of encoder by
Revision 2:82a12d9f0bca, committed 2018-03-27
- Comitter:
- frute8
- Date:
- Tue Mar 27 03:45:26 2018 +0000
- Parent:
- 1:6456080fa03b
- Commit message:
- a
Changed in this revision
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; -} - -
diff -r 6456080fa03b -r 82a12d9f0bca encoder.h --- a/encoder.h Mon Mar 26 20:42:49 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -#ifndef ENCODER_H -#define ENCODER_H - -#include "mbed.h" - -class Encoder{ -public : - Encoder(PinName APin, PinName BPin, PinName ZPin); - int read_rotate(); - int read_z(); - void init(); -private : - InterruptIn A; - DigitalIn B; - DigitalIn Z; - int count; - int zcount; - void flag(); -}; - -#endif -
diff -r 6456080fa03b -r 82a12d9f0bca encoder2.cpp --- /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; +} + +
diff -r 6456080fa03b -r 82a12d9f0bca encoder2.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/encoder2.h Tue Mar 27 03:45:26 2018 +0000 @@ -0,0 +1,22 @@ +#ifndef ENCODER_H2 +#define ENCODER_H2 + +#include "mbed.h" + +class Encoder2{ +public : + Encoder2(PinName APin, PinName BPin, PinName ZPin); + int read_rotate(); + int read_z(); + void init(); +private : + InterruptIn A; + DigitalIn B; + DigitalIn Z; + int count; + int zcount; + void flag(); +}; + +#endif +