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:
Wed May 04 16:14:30 2016 +0000
Revision:
3:c7011e72f0c7
Parent:
1:e34729a7567f
Revision, impl?mentation d?placement en mm

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 3:c7011e72f0c7 4 Stepper::Stepper(PinName _en, PinName _stepPin, PinName _dir, float step_per_mm):en(_en),
melse 0:52fb09e87581 5 stepPin(_stepPin),
sype 1:e34729a7567f 6 direction(_dir)
melse 0:52fb09e87581 7 {
sype 3:c7011e72f0c7 8 Step_Per_MM = step_per_mm;
melse 0:52fb09e87581 9 }
melse 0:52fb09e87581 10
sype 1:e34729a7567f 11 void Stepper::step(int number, int dir, float speed)
melse 0:52fb09e87581 12 {
melse 0:52fb09e87581 13 if (dir == 1) {
melse 0:52fb09e87581 14 direction = 0;
melse 0:52fb09e87581 15 } else if (dir == 0) {
melse 0:52fb09e87581 16 direction = 1;
melse 0:52fb09e87581 17 }
melse 0:52fb09e87581 18
melse 0:52fb09e87581 19 // Step...
sype 1:e34729a7567f 20 for(int i=0; i<number; i++)
sype 1:e34729a7567f 21 {
sype 1:e34729a7567f 22 stepPin = 1;
sype 1:e34729a7567f 23 wait_us(5);
sype 1:e34729a7567f 24 stepPin = 0;
sype 1:e34729a7567f 25 wait_us(5);
sype 1:e34729a7567f 26 wait(speed);
sype 1:e34729a7567f 27 }
melse 0:52fb09e87581 28 }
melse 0:52fb09e87581 29
sype 3:c7011e72f0c7 30 void Stepper::mm(int number, int dir)
sype 3:c7011e72f0c7 31 {
sype 3:c7011e72f0c7 32 step(number*Step_Per_MM, dir, DELAY-0.001);
sype 3:c7011e72f0c7 33 }
sype 3:c7011e72f0c7 34
sype 1:e34729a7567f 35 void Stepper::enable()
melse 0:52fb09e87581 36 {
melse 0:52fb09e87581 37 en = 0;
melse 0:52fb09e87581 38 }
melse 0:52fb09e87581 39
sype 1:e34729a7567f 40 void Stepper::disable()
melse 0:52fb09e87581 41 {
melse 0:52fb09e87581 42 en = 1;
melse 0:52fb09e87581 43 }