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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Stepper.cpp Source File

Stepper.cpp

00001 #include "Stepper.h"
00002 #include "mbed.h"
00003 
00004 stepper::stepper(PinName _en, PinName ms1, PinName ms2, PinName ms3, PinName _stepPin, PinName dir):en(_en),
00005     microstepping(ms1, ms2, ms3),
00006     stepPin(_stepPin),
00007     direction(dir)
00008 {
00009 }
00010 
00011 void stepper::step(int microstep, int dir, float speed)
00012 {
00013     if (microstep == 1) {
00014         microstepping = 0;
00015     } else if (microstep <= 4) {
00016         microstepping = microstep / 2;
00017     } else if (microstep > 4) {
00018         microstepping = (microstep / 2) - 1;
00019     }
00020     if (dir == 1) {
00021         direction = 0;
00022     } else if (dir == 0) {
00023         direction = 1;
00024     }
00025     
00026     //  Step...
00027     stepPin = 1;
00028     wait(1/speed);
00029     stepPin = 0;
00030     wait(1/speed);
00031 }
00032 
00033 void stepper::enable()
00034 {
00035     en = 0;
00036 }
00037 
00038 void stepper::disable()
00039 {
00040     en = 1;
00041 }