hezhian hezhain / armtest

Fork of stepper by Xiaoyuan Yu

Files at this revision

API Documentation at this revision

Comitter:
Dennis_Yu
Date:
Wed Jul 25 07:51:33 2018 +0000
Parent:
0:0774a793a83b
Child:
2:e537d08c705b
Commit message:
add funcs

Changed in this revision

stepper.cpp Show annotated file Show diff for this revision Revisions of this file
stepper.h Show annotated file Show diff for this revision Revisions of this file
--- a/stepper.cpp	Wed Jul 25 07:26:01 2018 +0000
+++ b/stepper.cpp	Wed Jul 25 07:51:33 2018 +0000
@@ -0,0 +1,30 @@
+#include "mbed.h"
+#include "stepper.h"
+
+void stepperMotor::init()
+{
+    remain = 0;
+    en = 0;
+    dir = 0;
+
+}
+
+void stepper::moveStepper()
+{
+    if(remain == 0)
+        return;
+    if(step)
+    {
+        step = 0; //STEP 1->0
+        remain--;
+    }
+    else
+    {
+        step = 1; //STEP 0->1
+    }
+}
+
+void stepper::stepperMotor(PinName stepPin, PinName dirPin, PinName enPin, float period):step(stepPin), dir(dirPin), en(enPin), remain(0)
+{
+    stepper.attach(&moveStepper, period);
+}
--- a/stepper.h	Wed Jul 25 07:26:01 2018 +0000
+++ b/stepper.h	Wed Jul 25 07:51:33 2018 +0000
@@ -6,14 +6,17 @@
 class stepperMotor
 {
   public:
+    int remain;
+    stepperMotor(){;}
+    stepperMotor(PinName stepPin, PinName dirPin, PinName enPin);
+//    step(stepPin),dir(dirPin),en(enPin), remain(0){;}
+    void init();
+    Ticker stepper;
+  private:
     DigitalOut step;
     DigitalOut dir;
     DigitalOut en;
-    int remain;
-    stepperMotor(PinName stepPin, PinName dirPin, PinName enPin):
-    step(stepPin),dir(dirPin),en(enPin), remain(0){;}
-    void init();
-    Ticker stepper;
+    void moveStepper();
 };
 
 #endif