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
Stepper.cpp
- Committer:
- sype
- Date:
- 2016-05-04
- Revision:
- 3:c7011e72f0c7
- Parent:
- 1:e34729a7567f
File content as of revision 3:c7011e72f0c7:
#include "Stepper.h" #include "mbed.h" 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) { if (dir == 1) { direction = 0; } else if (dir == 0) { direction = 1; } // Step... for(int i=0; i<number; 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::enable() { en = 0; } void Stepper::disable() { en = 1; }