Skip to main content
added 7 characters in body
Source Link
Holmez
  • 228
  • 1
  • 5

You could try something along these lines, I haven't put all of the code in, but just how this could be done for the sweep timer using millis().

unsigned long sweepTime;
unsigned long animationTime;
int stepperPosition;


void setup()
{
    //... other setup code
    sweepTime = millis();       // initialise the variables for the sweep timer, and the animation timer
    animationTime = millis();
    stepperPosition = 2000;     // initialise the next stepper position
}

void loop()
{
    if (millis() - sweepTime > 500) //  check if more than 500 milliseconds have elapsed since last time we ran this.
    {
        stepper.runToNewPosition(stepperPosition);  // change stepper position
        sweepTime = millis();           // reset timer variable
        switch (stepperPosition) {      // need to change the value of the next position to set the stepper to
            case 0 : 
                stepperPosition = 2000;
                break;
            case 2000 :
                stepperPosition = 0;
                break;
        }
    }
    //... continuation of loop code
}

Additionally, I don't have my arduino with me, so can't verify the correctness of the code.

You could try something along these lines, I haven't put all of the code in, but just how this could be done for the sweep timer using millis().

long sweepTime;
long animationTime;
int stepperPosition;


void setup()
{
    //... other setup code
    sweepTime = millis();       // initialise the variables for the sweep timer, and the animation timer
    animationTime = millis();
    stepperPosition = 2000;     // initialise the next stepper position
}

void loop()
{
    if (millis() - sweepTime > 500) //  check if more than 500 milliseconds have elapsed since last time we ran this.
    {
        stepper.runToNewPosition(stepperPosition);  // change stepper position
        sweepTime = millis();           // reset timer variable
        switch (stepperPosition) {      // need to change the value of the next position to set the stepper to
            case 0 : 
                stepperPosition = 2000;
                break;
            case
                stepperPosition = 0;
                break;
        }
    }
    //... continuation of loop code
}

Additionally, I don't have my arduino with me, so can't verify the correctness of the code.

You could try something along these lines, I haven't put all of the code in, but just how this could be done for the sweep timer using millis().

unsigned long sweepTime;
unsigned long animationTime;
int stepperPosition;


void setup()
{
    //... other setup code
    sweepTime = millis();       // initialise the variables for the sweep timer, and the animation timer
    animationTime = millis();
    stepperPosition = 2000;     // initialise the next stepper position
}

void loop()
{
    if (millis() - sweepTime > 500) //  check if more than 500 milliseconds have elapsed since last time we ran this.
    {
        stepper.runToNewPosition(stepperPosition);  // change stepper position
        sweepTime = millis();           // reset timer variable
        switch (stepperPosition) {      // need to change the value of the next position to set the stepper to
            case 0 : 
                stepperPosition = 2000;
                break;
            case 2000 :
                stepperPosition = 0;
                break;
        }
    }
    //... continuation of loop code
}

Additionally, I don't have my arduino with me, so can't verify the correctness of the code.

Source Link
Holmez
  • 228
  • 1
  • 5

You could try something along these lines, I haven't put all of the code in, but just how this could be done for the sweep timer using millis().

long sweepTime;
long animationTime;
int stepperPosition;


void setup()
{
    //... other setup code
    sweepTime = millis();       // initialise the variables for the sweep timer, and the animation timer
    animationTime = millis();
    stepperPosition = 2000;     // initialise the next stepper position
}

void loop()
{
    if (millis() - sweepTime > 500) //  check if more than 500 milliseconds have elapsed since last time we ran this.
    {
        stepper.runToNewPosition(stepperPosition);  // change stepper position
        sweepTime = millis();           // reset timer variable
        switch (stepperPosition) {      // need to change the value of the next position to set the stepper to
            case 0 : 
                stepperPosition = 2000;
                break;
            case
                stepperPosition = 0;
                break;
        }
    }
    //... continuation of loop code
}

Additionally, I don't have my arduino with me, so can't verify the correctness of the code.