This drive is working well with "LPD3806-600BM-G5-24G", and have Simple program

Dependencies:   mbed

Revision:
0:b2ffb830539c
Child:
3:6a91d523b146
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Rotary_Encoder.cpp	Sat Feb 02 21:19:30 2019 +0000
@@ -0,0 +1,52 @@
+#include "Rotary_Encoder.h"
+
+Rotary_Encoder::Rotary_Encoder(PinName White, PinName Green) : Green_Pin(Green), White_Pin(White)
+{
+    Green_Pin.rise(this, &Rotary_Encoder::Green_Pin_Rise);
+    White_Pin.rise(this, &Rotary_Encoder::White_Pin_Rise);
+}
+
+void Rotary_Encoder::Green_Pin_Rise(void)
+{
+    if(White_Pin.read() == 0)
+        Encoder_Counter++;
+    else
+        Encoder_Counter--;
+}
+    
+void Rotary_Encoder::White_Pin_Rise(void)
+{
+    if(Green_Pin.read() == 0)
+        Encoder_Counter--;
+    else
+        Encoder_Counter++;
+}
+
+char *Rotary_Encoder::Calculate_Direction(void)
+{
+    // Data processing    -2^32< "int" <2^32-1
+    while(Encoder_Counter < -1275)
+        Encoder_Counter = Encoder_Counter + 1200;
+    while(Encoder_Counter > 1275)
+        Encoder_Counter = Encoder_Counter - 1200;
+    
+    // Calculate the direction
+    if(((-1275<=Encoder_Counter)&&(Encoder_Counter<=-1126)) ||  ((-76 <= Encoder_Counter)&&(Encoder_Counter <= 75)) || ((1126 <= Encoder_Counter)&&(Encoder_Counter <= 1275)))
+        strcpy(Direction,"N");  // N 北
+    else if (((76 <= Encoder_Counter)&&(Encoder_Counter <= 225)) || ((-1126 <= Encoder_Counter)&&(Encoder_Counter <= -975)))
+        strcpy(Direction,"NE"); // NE 东北
+    else if (((226 <= Encoder_Counter)&&(Encoder_Counter <= 375)) || ((-976 <= Encoder_Counter)&&(Encoder_Counter <= -825)))
+        strcpy(Direction,"E");  // E  东
+    else if (((376 <= Encoder_Counter)&&(Encoder_Counter <= 525)) || ((-826 <= Encoder_Counter)&&(Encoder_Counter <= -675)))
+        strcpy(Direction,"SE"); // SE 东南
+    else if (((526 <= Encoder_Counter)&&(Encoder_Counter <= 675)) || ((-676 <= Encoder_Counter)&&(Encoder_Counter <= -525)))
+        strcpy(Direction,"S");  // S  南
+    else if (((676 <= Encoder_Counter)&&(Encoder_Counter <= 825)) || ((-526 <= Encoder_Counter)&&(Encoder_Counter <= -375)))
+        strcpy(Direction,"SW"); // SW 西南
+    else if (((826 <= Encoder_Counter)&&(Encoder_Counter <= 975)) || ((-376 <= Encoder_Counter)&&(Encoder_Counter <= -225)))
+        strcpy(Direction,"W");  // W  西
+    else if (((927 <= Encoder_Counter)&&(Encoder_Counter <= 1125)) || ((-226 <= Encoder_Counter)&&(Encoder_Counter <= -75)))
+        strcpy(Direction,"NW"); // NW 西北
+    
+    return Direction;
+}