Rauno U
/
Miisu
Six crescent shaped legs
Diff: Encoder.cpp
- Revision:
- 2:cf0147952fb9
- Child:
- 8:c3af2a1c206c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Encoder.cpp Tue Mar 29 12:03:14 2016 +0000 @@ -0,0 +1,20 @@ +#include "Encoder.hpp" + +Encoder::Encoder(PinName encAPin, PinName encBPin) : encA(encAPin), encB(encBPin), intA(encAPin), intB(encBPin) +{ + intA.rise(this, &Encoder::changeA); + intA.fall(this, &Encoder::changeA); +} + +long Encoder::getCount() +{ + return count; +} + +void Encoder::changeA() +{ + if (encA.read() == encB.read()) + count++; + else + count--; +} \ No newline at end of file