Fork van Victor Sluiters library. Output van speed is nu een double i.p.v. float.
Fork of Encoder by
Diff: encoder.h
- Revision:
- 1:2dd7853c911a
- Parent:
- 0:c90b36abcbf8
- Child:
- 2:c27f6d0ec1ae
diff -r c90b36abcbf8 -r 2dd7853c911a encoder.h --- a/encoder.h Wed Sep 25 14:55:08 2013 +0000 +++ b/encoder.h Tue Oct 01 21:47:15 2013 +0000 @@ -2,13 +2,42 @@ #define _ENCODER_H_ #include "mbed.h" - +/** Encoder class. + * Used to read out incremental position encoder. Decodes position in X2 configuration. + * + * Example: + * @code + * #include "mbed.h" + * #include "Encoder.h" + * + * Encoder motor1(PTD0,PTC9); + * Serial pc(USBTX,USBRX); + * pc.baud(115200); + * while(1) { + * wait(0.2); + * pc.printf("pos: %d, speed %f \r\n",motor1.getPosition(), motor1.getSpeed()); + * } + * @endcode + */ class Encoder { public: + /** Create Encoder instance + @param int_a Pin to be used as InterruptIn! Be careful, as not all pins on all platforms may be used as InterruptIn. + @param int_b second encoder pin, used as DigitalIn. Can be any DigitalIn pin, not necessarily on InterruptIn location + */ Encoder(PinName int_a, PinName int_b); + /** Request position + @returns current position in encoder counts + */ int32_t getPosition(){return m_position;} + /** Overwrite position + @param pos position to be written + */ void setPosition(int32_t pos){m_position = pos;} + /** Request speed + @returns current speed + */ float getSpeed(){return m_speed;} private: void encoderFalling(void);