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.
Dependencies: RoboClaw mbed StepperMotor
Fork of RoboClaw by
Diff: StepperMotor/Stepper.cpp
- Revision:
- 58:02dc8328975a
- Child:
- 71:5590dbe8393a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/StepperMotor/Stepper.cpp Wed May 04 19:55:03 2016 +0000
@@ -0,0 +1,50 @@
+#include "defines.h"
+#include "Stepper.h"
+#include "mbed.h"
+
+Stepper::Stepper(PinName _en, PinName _stepPin, PinName _dir, PinName _minEndStop, float step_per_mm):en(_en),
+ stepPin(_stepPin),
+ direction(_dir),
+ minEndStop(_minEndStop)
+{
+ Step_Per_MM = step_per_mm;
+}
+
+void Stepper::step(int number, int dir, float speed)
+{
+ if (dir == HAUT) {
+ direction = 0;
+ } else if (dir == BAS) {
+ direction = 1;
+ }
+
+ // Step...
+ for(int i=0; i<number && !(minEndStop.read() == 0 && dir == BAS); i++)
+ {
+ stepPin = 1;
+ wait_us(5);
+ stepPin = 0;
+ wait_us(5);
+ wait(speed);
+ }
+}
+
+void Stepper::mm(int number, int dir)
+{
+ step(number*Step_Per_MM, dir, DELAY-0.001);
+}
+
+void Stepper::mm(float distance)
+{
+ step(abs(distance*Step_Per_MM), (distance>0?HAUT:BAS), DELAY-0.001);
+}
+
+void Stepper::enable()
+{
+ en = 0;
+}
+
+void Stepper::disable()
+{
+ en = 1;
+}
\ No newline at end of file
