counter.h
- Committer:
- daveTshave
- Date:
- 2011-11-25
- Revision:
- 0:f4c92b67e7be
- Child:
- 1:8c1bace3af7b
File content as of revision 0:f4c92b67e7be:
#ifndef counter_H #define counter_H /** * Includes */ #include "mbed.h" /** * Simple counter */ class counter { public: /** * Constructor. * * Attaches the encode function to the rise/fall edge of * channels A. * * @param channelA mbed pin for counter input. * @param pulsesPerRev Number of pulses in one revolution. */ counter(PinName channelA,int pulsesPerRev); /** * Reset the encoder. * * Sets the pulses and revolutions count to zero. */ void reset(void); /** * Read the number of pulses recorded by the encoder. * * @return Number of pulses which have occured. */ int getPulses(void); /** * Read the number of revolutions recorded by the encoder on the index channel. * * @return Number of revolutions which have occured on the index channel. */ int getRevolutions(void); private: /** * Update the pulse count. * * Called on every rising edge of channels A. * */ void encode(void); InterruptIn channelA_; int pulsesPerRev_; volatile int pulses_; volatile int revolutions_; }; #endif /* counter_H */