encoder library
Diff: Encoder.h
- Revision:
- 0:33005fa67bfd
- Child:
- 2:10ce3d24df8e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Encoder.h Thu Dec 13 08:19:50 2018 +0000 @@ -0,0 +1,43 @@ +#ifndef ENCODER_H +#define ENCODER_H + +#include "mbed.h" + +/****定数****/ +#define PI 3.1415f +#define RADIAN 360 +#define MINUTE 60 +#define CALCULATE_PERIOD 0.01f + +enum DATA_CATEGORY{ + COUNT, + ROTATION, + RPM, + DISTANCE, + ANGLE, + POSITION, +}; + + +class Encoder { + public: + Encoder(PinName Apulse,PinName Bpulse); + void setup(int Ppr = 400,int Diameter = 0); + void calculate(); + float getData(short ch); + + private: + InterruptIn Apulse; + InterruptIn Bpulse; + Ticker RpmCalculateTimer; + + void Apulse_Up(); + void Apulse_Down(); + void Bpulse_Up(); + void Bpulse_Down(); + void RpmCalculate(); + + float PPR,DIAMETER,count,rotation,rpm,distance,angle,position; +}; + +#endif \ No newline at end of file