Go Down

Topic: {solved}problem with While Loop (Read 305 times) previous topic - next topic

MurdockGT

Aug 01, 2016, 06:52 pm Last Edit: Aug 01, 2016, 08:20 pm by MurdockGT
I am having an issue with this while loop for the stepperHome function.  It is called once on bootup.  It moves the -100 steps back, but then the program stops there, until i manually hit the endstop.  It is supposed to loop and move back -100 until it hits the endstops.

Am i missing something?
Code: [Select]
#include <AccelStepper.h>

AccelStepper stepper1(1, 9, 8);

const int homeButton = 19;
byte hBval;


void setup(){
  Serial.begin(9600); // For debugging
  stepper1.setMaxSpeed(500); //nice and slow for testing
  stepper1.moveTo(-3200);
  stepper1.setAcceleration(500);
  pinMode(homeButton, INPUT_PULLUP);
 
  stepperHome(); //runs routine to home motor
}
void loop(){
    stepper1.moveTo(46000); // random position to end for testing
  stepper1.runToPosition();
  delay(1000);
  stepper1.moveTo(0);
  stepper1.runToPosition();
  delay(1000);
}



void stepperHome()
{ //this routine should run the motor
   // this could be in setup()
                                   // before calling stepperHome function
  hBval = digitalRead(homeButton);
  while (hBval == HIGH)
  {
    //backwards slowly till it hits the switch and stops
    stepper1.moveTo(-100);
    stepper1.run();
    hBval = digitalRead(homeButton);
  }
 
  stepper1.setCurrentPosition(0); //
}

MurdockGT

got it,  moveto needed to be move() .

Always somethign simple

Go Up