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

Dependents:   tes_stepper Test_all

Stepper Motor Driver, designed for use with the Pololu A4988 breakout, however more than likely compatible with, for example the Sparkfun Easy Driver

Revision:
0:52fb09e87581
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Stepper.cpp	Sun Feb 24 16:23:02 2013 +0000
@@ -0,0 +1,41 @@
+#include "Stepper.h"
+#include "mbed.h"
+
+stepper::stepper(PinName _en, PinName ms1, PinName ms2, PinName ms3, PinName _stepPin, PinName dir):en(_en),
+    microstepping(ms1, ms2, ms3),
+    stepPin(_stepPin),
+    direction(dir)
+{
+}
+
+void stepper::step(int microstep, int dir, float speed)
+{
+    if (microstep == 1) {
+        microstepping = 0;
+    } else if (microstep <= 4) {
+        microstepping = microstep / 2;
+    } else if (microstep > 4) {
+        microstepping = (microstep / 2) - 1;
+    }
+    if (dir == 1) {
+        direction = 0;
+    } else if (dir == 0) {
+        direction = 1;
+    }
+    
+    //  Step...
+    stepPin = 1;
+    wait(1/speed);
+    stepPin = 0;
+    wait(1/speed);
+}
+
+void stepper::enable()
+{
+    en = 0;
+}
+
+void stepper::disable()
+{
+    en = 1;
+}
\ No newline at end of file