diff --git a/CheapStepper.cpp b/CheapStepper.cpp index 914cd91..21eb7d3 100644 --- a/CheapStepper.cpp +++ b/CheapStepper.cpp @@ -136,10 +136,10 @@ void CheapStepper::run(){ if (micros() - lastStepTime >= delay) { // if time for step if (stepsLeft > 0) { // clockwise - stepCW(); + stepCW(false); stepsLeft--; } else if (stepsLeft < 0){ // counter-clockwise - stepCCW(); + stepCCW(false); stepsLeft++; } @@ -153,10 +153,13 @@ void CheapStepper::stop(){ } -void CheapStepper::step(bool clockwise){ +void CheapStepper::step(bool clockwise, bool block){ if (clockwise) seqCW(); else seqCCW(); + if(block) { + delayMicroseconds(delay); + } } void CheapStepper::off() { @@ -293,7 +296,6 @@ void CheapStepper::seq (int seqNum){ for (int p=0; p<4; p++){ digitalWrite(pins[p], pattern[p]); } - delayMicroseconds(delay); } diff --git a/CheapStepper.h b/CheapStepper.h index eb29df7..68fdf1a 100644 --- a/CheapStepper.h +++ b/CheapStepper.h @@ -80,11 +80,11 @@ class CheapStepper - void step (bool clockwise); + void step (bool clockwise, bool block = true); // move 1 step clockwise or counter-clockwise - void stepCW () { step (true); } // move 1 step clockwise - void stepCCW () { step (false); } // move 1 step counter-clockwise + void stepCW (bool block = true) { step (true, block); } // move 1 step clockwise + void stepCCW (bool block = true) { step (false, block); } // move 1 step counter-clockwise int getStep() { return stepN; } // returns current miniStep position int getDelay() { return delay; } // returns current delay (microseconds)