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
Diff: Stepper.cpp
- Revision:
- 1:e34729a7567f
- Parent:
- 0:52fb09e87581
- Child:
- 3:c7011e72f0c7
diff -r 52fb09e87581 -r e34729a7567f Stepper.cpp --- a/Stepper.cpp Sun Feb 24 16:23:02 2013 +0000 +++ b/Stepper.cpp Tue Apr 05 14:58:59 2016 +0000 @@ -1,22 +1,14 @@ #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), +Stepper::Stepper(PinName _en, PinName _stepPin, PinName _dir):en(_en), stepPin(_stepPin), - direction(dir) + direction(_dir) { } -void stepper::step(int microstep, int dir, float speed) +void Stepper::step(int number, 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) { @@ -24,18 +16,22 @@ } // Step... - stepPin = 1; - wait(1/speed); - stepPin = 0; - wait(1/speed); + for(int i=0; i<number; i++) + { + stepPin = 1; + wait_us(5); + stepPin = 0; + wait_us(5); + wait(speed); + } } -void stepper::enable() +void Stepper::enable() { en = 0; } -void stepper::disable() +void Stepper::disable() { en = 1; } \ No newline at end of file