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

Committer:
sype
Date:
Tue Apr 05 14:58:59 2016 +0000
Revision:
1:e34729a7567f
Parent:
0:52fb09e87581
Child:
3:c7011e72f0c7
RAZ

Who changed what in which revision?

UserRevisionLine numberNew contents of line
melse 0:52fb09e87581 1 #include "Stepper.h"
melse 0:52fb09e87581 2 #include "mbed.h"
melse 0:52fb09e87581 3
sype 1:e34729a7567f 4 Stepper::Stepper(PinName _en, PinName _stepPin, PinName _dir):en(_en),
melse 0:52fb09e87581 5 stepPin(_stepPin),
sype 1:e34729a7567f 6 direction(_dir)
melse 0:52fb09e87581 7 {
melse 0:52fb09e87581 8 }
melse 0:52fb09e87581 9
sype 1:e34729a7567f 10 void Stepper::step(int number, int dir, float speed)
melse 0:52fb09e87581 11 {
melse 0:52fb09e87581 12 if (dir == 1) {
melse 0:52fb09e87581 13 direction = 0;
melse 0:52fb09e87581 14 } else if (dir == 0) {
melse 0:52fb09e87581 15 direction = 1;
melse 0:52fb09e87581 16 }
melse 0:52fb09e87581 17
melse 0:52fb09e87581 18 // Step...
sype 1:e34729a7567f 19 for(int i=0; i<number; i++)
sype 1:e34729a7567f 20 {
sype 1:e34729a7567f 21 stepPin = 1;
sype 1:e34729a7567f 22 wait_us(5);
sype 1:e34729a7567f 23 stepPin = 0;
sype 1:e34729a7567f 24 wait_us(5);
sype 1:e34729a7567f 25 wait(speed);
sype 1:e34729a7567f 26 }
melse 0:52fb09e87581 27 }
melse 0:52fb09e87581 28
sype 1:e34729a7567f 29 void Stepper::enable()
melse 0:52fb09e87581 30 {
melse 0:52fb09e87581 31 en = 0;
melse 0:52fb09e87581 32 }
melse 0:52fb09e87581 33
sype 1:e34729a7567f 34 void Stepper::disable()
melse 0:52fb09e87581 35 {
melse 0:52fb09e87581 36 en = 1;
melse 0:52fb09e87581 37 }