zhouhang shao
/
test
test
Diff: encoder.h
- Revision:
- 3:34a763e93423
- Parent:
- 2:b78dfa2afe92
- Child:
- 6:9f698d1b2996
--- a/encoder.h Sat May 06 23:10:06 2017 +0000 +++ b/encoder.h Sun May 07 01:31:52 2017 +0000 @@ -1,43 +1,43 @@ -//#ifndef ENCODER_H -//#define ENCODER_H -//#include "mbed.h" -// -///* -//* Reset both encoders -//*/ -//void resetEncoders(); -// -///* -//Returns the average number of pulses across both encoders since last reset. Unit is encoder pulses; intended for straight driving only. -//*/ -//int getEncoderDistance(); -// -// -//class Encoder { -//public: -// volatile int pulses; -// -// Encoder(PinName channelA, PinName channelB); -// -// //Reset the encoder -// void reset(void); -// -// //Gets pulses by directly querying the encoder. -// operator int() { -// return pulses; -// } -// -//private: -// InterruptIn channelA_; -// InterruptIn channelB_; -// int prevState_; -// int currState_; -// -// void encode(void); -//}; -// -// -//extern Encoder leftEncoder; -// -// -//#endif \ No newline at end of file +#ifndef ENCODER_H +#define ENCODER_H +#include "mbed.h" + +/* +* Reset both encoders +*/ +void resetEncoders(); + +/* +Returns the average number of pulses across both encoders since last reset. Unit is encoder pulses; intended for straight driving only. +*/ +int getEncoderDistance(); + + +class Encoder { +public: + volatile int pulses; + + Encoder(PinName channelA, PinName channelB); + + //Reset the encoder + void reset(void); + + //Gets pulses by directly querying the encoder. + operator int() { + return pulses; + } + +private: + InterruptIn channelA_; + InterruptIn channelB_; + int prevState_; + int currState_; + + void encode(void); +}; + + +extern Encoder leftEncoder; + + +#endif \ No newline at end of file