hezhian hezhain / armtest

Fork of stepper by Xiaoyuan Yu

Revision:
2:e537d08c705b
Parent:
1:bbb51c42e7d2
Child:
3:fd565358f888
--- a/stepper.cpp	Wed Jul 25 07:51:33 2018 +0000
+++ b/stepper.cpp	Wed Jul 25 08:25:10 2018 +0000
@@ -1,15 +1,7 @@
 #include "mbed.h"
 #include "stepper.h"
 
-void stepperMotor::init()
-{
-    remain = 0;
-    en = 0;
-    dir = 0;
-
-}
-
-void stepper::moveStepper()
+void stepperMotor::moveStepper()
 {
     if(remain == 0)
         return;
@@ -24,7 +16,35 @@
     }
 }
 
-void stepper::stepperMotor(PinName stepPin, PinName dirPin, PinName enPin, float period):step(stepPin), dir(dirPin), en(enPin), remain(0)
+void stepperMotor::enable()
+{
+    en = 0;
+}
+
+void stepperMotor::enable(int inputRemain)
+{
+    remain = inputRemain;
+    enable();
+}
+
+void stepperMotor::disable()
 {
-    stepper.attach(&moveStepper, period);
+    remain = 0;
+    en = 1;
+}
+
+void stepperMotor::pause()
+{
+    en = 1;
 }
+
+void stepperMotor::setDir(bool direction)
+{
+    dir = direction;
+}
+
+stepperMotor::stepperMotor(PinName stepPin, PinName dirPin, PinName enPin, float period): remain(0), step(stepPin), dir(dirPin), en(enPin)
+{
+    disable();
+    stepper.attach(this, &stepperMotor::moveStepper, period);
+}