A simple stepper motor driver library, supporting micro-stepping drivers such as the Pololu A4988 stepper driver carrier or the Sparkfun EasyDriver.

Dependents:   Robot2016_2-0_STATIC Robot2016_2-0

Fork of StepperMotor by Matthew Else

Files at this revision

API Documentation at this revision

Comitter:
sype
Date:
Wed May 04 16:14:30 2016 +0000
Parent:
2:1cec7e9117f2
Commit message:
Revision, impl?mentation d?placement en mm

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
diff -r 1cec7e9117f2 -r c7011e72f0c7 Stepper.cpp
--- a/Stepper.cpp	Wed Apr 13 11:26:35 2016 +0000
+++ b/Stepper.cpp	Wed May 04 16:14:30 2016 +0000
@@ -1,10 +1,11 @@
 #include "Stepper.h"
 #include "mbed.h"
 
-Stepper::Stepper(PinName _en, PinName _stepPin, PinName _dir):en(_en),
+Stepper::Stepper(PinName _en, PinName _stepPin, PinName _dir, float step_per_mm):en(_en),
     stepPin(_stepPin),
     direction(_dir)
 {
+    Step_Per_MM = step_per_mm;
 }
 
 void Stepper::step(int number, int dir, float speed)
@@ -26,6 +27,11 @@
     }
 }
 
+void Stepper::mm(int number, int dir)
+{
+    step(number*Step_Per_MM, dir, DELAY-0.001);
+}
+
 void Stepper::enable()
 {
     en = 0;
diff -r 1cec7e9117f2 -r c7011e72f0c7 Stepper.h
--- a/Stepper.h	Wed Apr 13 11:26:35 2016 +0000
+++ b/Stepper.h	Wed May 04 16:14:30 2016 +0000
@@ -8,10 +8,13 @@
 class Stepper
 {
 public:
-    Stepper(PinName _en, PinName _stepPin, PinName dir);
+    Stepper(PinName _en, PinName _stepPin, PinName dir, float step_per_mm);
     void step(int number, int dir, float speed);
+    void mm(int number, int dir);
     void enable();
     void disable();
+    
+    float Step_Per_MM;
 private:
     DigitalOut en;
     DigitalOut stepPin;