Rotary encoder handler.

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RotaryEncoder.h Source File

RotaryEncoder.h

00001 #include "mbed.h"
00002 
00003 #ifndef ROTARY_ENCODER_H_
00004 #define ROTARY_ENCODER_H_
00005 
00006 /**
00007  Rotary encoder handling class.
00008  Starts a ticker which checks the status of the encoder and
00009  sets the rotation directions based on its status.
00010 */
00011 class RotaryEncoder {
00012 public:
00013     RotaryEncoder(void (*cb)(void), PinName channelA_, PinName channelB_, PinName pushPin_, float period = 0.01);
00014     virtual ~RotaryEncoder();
00015     
00016     /// Retrieve rotation direction.
00017     int8_t getDirection() const;
00018     /// Retrieve push button status.
00019     bool getPushButton() const;
00020     /// Launched by Ticker to determine rotation direction
00021     void pulse();
00022     
00023     int getCounter() const;
00024     
00025     private:
00026     
00027     /// Table which helps determine the rotation direction
00028     static const int8_t encoderTable[];
00029 
00030     int counter;
00031     int8_t direction;
00032     int8_t lastDirection;
00033     InterruptIn channelA;
00034     InterruptIn channelB;
00035     InterruptIn pushPin;
00036     Ticker encoderTicker;
00037     
00038 };
00039 
00040 #endif /* ROTARY_ENCODER_H_ */