Library for decoding quadrature encoders. Uses a ring buffer so you can be sure to process every tick in the order that it happened. This library is not really intended for public use yet and does not have much documentation.
Dependents: LineFollowing DeadReckoning
Diff: PololuEncoder.h
- Revision:
- 2:22ac2b4a8012
- Parent:
- 1:138f5421c287
- Child:
- 3:a2dd8d8bde4c
--- a/PololuEncoder.h Thu Feb 20 18:54:43 2014 +0000 +++ b/PololuEncoder.h Thu Feb 20 20:09:21 2014 +0000 @@ -46,15 +46,16 @@ PololuEncoder(PinName pinNameA, PinName pinNameB, PololuEncoderBuffer * buffer, uint8_t id) : pinA(pinNameA), pinB(pinNameB), buffer(buffer), id(id) { - pinA.mode(PullUp); // TODO: move this to the user code - pinB.mode(PullUp); // TODO: move this to the user code - + } + + void init() + { pinA.rise(this, &PololuEncoder::isr); pinA.fall(this, &PololuEncoder::isr); pinB.rise(this, &PololuEncoder::isr); pinB.fall(this, &PololuEncoder::isr); - previousState = readState(); + count = 0; } void isr() @@ -86,7 +87,7 @@ } previousState = newState; - if (event != 0 && buffer->hasSpace()) + if (event != 0 && buffer != NULL && buffer->hasSpace()) { buffer->writeEvent(event); }