ARES
/
Timer
Time is good
Fork of Robot2016_2-0 by
StepperMotor/Stepper.cpp
- Committer:
- Jagang
- Date:
- 2016-05-04
- Revision:
- 58:02dc8328975a
- Child:
- 71:5590dbe8393a
File content as of revision 58:02dc8328975a:
#include "defines.h" #include "Stepper.h" #include "mbed.h" Stepper::Stepper(PinName _en, PinName _stepPin, PinName _dir, PinName _minEndStop, float step_per_mm):en(_en), stepPin(_stepPin), direction(_dir), minEndStop(_minEndStop) { Step_Per_MM = step_per_mm; } void Stepper::step(int number, int dir, float speed) { if (dir == HAUT) { direction = 0; } else if (dir == BAS) { direction = 1; } // Step... for(int i=0; i<number && !(minEndStop.read() == 0 && dir == BAS); 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::mm(float distance) { step(abs(distance*Step_Per_MM), (distance>0?HAUT:BAS), DELAY-0.001); } void Stepper::enable() { en = 0; } void Stepper::disable() { en = 1; }