BieWang / stepper

Fork of stepper by Xiaoyuan Yu

Revision:
1:bbb51c42e7d2
Parent:
0:0774a793a83b
Child:
2:e537d08c705b
diff -r 0774a793a83b -r bbb51c42e7d2 stepper.cpp
--- 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);
+}