ddd

Fork of stepper by Biy Bill

Revision:
1:88f743f3e7a7
Parent:
0:173936452e07
Child:
2:e9699816ff84
--- a/a4988.cpp	Wed May 02 10:48:23 2018 +0000
+++ b/a4988.cpp	Fri May 11 06:05:21 2018 +0000
@@ -6,8 +6,7 @@
 {
     
 }
- 
-void Stepper::step(int dir, int frequency ,volatile int _remain)
+void Stepper::step(int dir, long long int frequency ,volatile long long int _remain)
 {
     //fun = &Stepper::step_control;
     if (dir == 1) {
@@ -16,7 +15,7 @@
         direction = 1;
     }
     remain = _remain;
-    step_ticker.attach(this, &Stepper::step_control,1.0/frequency);
+    step_ticker.attach(this, &Stepper::step_control,0.5/frequency);
 }
  
 void Stepper::enable()
@@ -35,11 +34,19 @@
         {         
             return;
         }
-        
-                if(stepPin){
-                        stepPin = 0; //STEP 1->0
-                        remain--;
-                }else{
-                        stepPin = 1; //STEP 0->1
-                }
+        if(remain < 0 )
+        {
+            if(stepPin){
+                stepPin = 0; //STEP 1->0
+            }else{
+                stepPin = 1; //STEP 0->1
+            }
+        }
+            
+        if(stepPin){
+            stepPin = 0; //STEP 1->0
+            remain--;
+        }else{
+            stepPin = 1; //STEP 0->1
+        }
 }