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

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Yifan_Du
Date:
Tue Feb 19 05:31:32 2019 +0000
Parent:
2:7d34758c3cc4
Commit message:
Add return 'float' function

Changed in this revision

Rotary_Encoder.cpp Show annotated file Show diff for this revision Revisions of this file
Rotary_Encoder.h Show annotated file Show diff for this revision Revisions of this file
--- a/Rotary_Encoder.cpp	Fri Feb 08 07:11:22 2019 +0000
+++ b/Rotary_Encoder.cpp	Tue Feb 19 05:31:32 2019 +0000
@@ -22,7 +22,27 @@
         Encoder_Counter++;
 }
 
-char *Rotary_Encoder::Calculate_Direction(void)
+float Rotary_Encoder::Calculate_Direction(void)
+{
+    while(Encoder_Counter < -1200)
+        Encoder_Counter = Encoder_Counter + 1200;
+    while(Encoder_Counter > 1200)
+        Encoder_Counter = Encoder_Counter - 1200;
+    
+    if(Encoder_Counter <0 )
+    {
+        Direction_Numb = ((Encoder_Counter / 1200.0) * 360.0f )+ 360.0f;
+    }
+    else
+    {
+        Direction_Numb = (Encoder_Counter / 1200.0) * 360.0f;
+    }
+    
+    return Direction_Numb;
+}
+
+
+char *Rotary_Encoder::Show_Direction_In_char(void)
 {
     // Data processing    -2^32< "int" <2^32-1
     while(Encoder_Counter < -1275)
@@ -50,3 +70,6 @@
     
     return Direction;
 }
+
+
+
--- a/Rotary_Encoder.h	Fri Feb 08 07:11:22 2019 +0000
+++ b/Rotary_Encoder.h	Tue Feb 19 05:31:32 2019 +0000
@@ -19,10 +19,10 @@
     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     THE SOFTWARE.
  
-    
-    1.0 2-Feb.-2019 - Initial release.
+        1.1     19-Feb.-2019    Add return 'float' function
+        1.0     2-Feb.-2019     Initial release.
         
-  *****************************************************************
+    *****************************************************************
   Attention: This drive is working well with "LPD3806-600GM-G5-24G'
   *****************************************************************
   @code
@@ -53,23 +53,26 @@
 class Rotary_Encoder 
 {
     private:
-        char        Direction[5];   
-        int         Encoder_Counter;
-        InterruptIn Green_Pin, White_Pin;
+        char                    Direction[5];   
+        int                     Encoder_Counter;
+        float         Direction_Numb;
+        InterruptIn     Green_Pin, White_Pin;
     
-    public:
-        Rotary_Encoder(PinName White, PinName Green);
-        // @Param  White  The pin whitch is connected to the encoder white line.
-        // @Param  Green    The pin whitch is connected to the encoder green line.
-        
         void Green_Pin_Rise(void);
         // Change 'Encoder_Direction' when detecting voltage in 'Green Pin' from LOW to HIGH.
     
         void White_Pin_Rise(void);
         // Change 'Encoder_Direction' when detecting voltage in 'White Pin' from LOW to HIGH.
     
-        char *Calculate_Direction(void);
+    public:
+        Rotary_Encoder(PinName White, PinName Green);
+        // @Param  White  The pin whitch is connected to the encoder white line.
+        // @Param  Green    The pin whitch is connected to the encoder green line.
+    
+        char *Show_Direction_In_char(void);
         // Return Direciton.
+    
+        float Calculate_Direction(void);
 };
 
 #endif