Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of stepper by
Revision 1:bbb51c42e7d2, committed 2018-07-25
- 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
