stepper code, trouble with adding home position code

Hi, ive been working on a 2 button stepper code for sometime now, after reading other posts and codes, I think it would be important to have a home position set also. ive managed to have the button control portion working, but not sure where to place the homeposition part. ive read a post that suggested this logic...

S.SetSpeed(somethingslow) ; S.step(3) ; // move forward a little in case we already ar at home. while (digitalRead(pinwithswitch)==HIGH) S.step(-1) ; // Stepper at home position

This is the direction id like to go. Would this be put into a separate loop() before my code? it shouldn't be placed within the code that is already there...so, How would this run once then exit and wait for my button presses?

hope my questions make sense?

Jeff

Stepper stepper(STEPS, 9, 10, 11, 12)

void setup() { pinMode(buttonPin1, INPUT); pinMode(buttonPin2, INPUT); pinMode(homeButton, INPUT); stepper.setSpeed(60); }

void loop() }

buttonState1 = digitalRead(buttonPin1); // read the state of the pushbutton value buttonState2 = digitalRead(buttonPin2); // read the state of the pushbutton value if(digitalRead(buttonPin1) == HIGH) { stepper.step(STEPS); } //check button pressed, if so enter program condition (inside if statement) if(digitalRead(buttonPin2) == HIGH) { stepper.setCurrentPosition(0); } }

Stepper stepper(STEPS, 9, 10, 11, 12)


void setup()
{
  pinMode(buttonPin1, INPUT);  
  pinMode(buttonPin2, INPUT);
  pinMode(homeButton, INPUT);
  stepper.setSpeed(60);
}

void loop()
}

  buttonState1 = digitalRead(buttonPin1); // read the state of the pushbutton value
  buttonState2 = digitalRead(buttonPin2); // read the state of the pushbutton value
   if(digitalRead(buttonPin1) == HIGH) 
   {
  stepper.step(STEPS);
   }
 //check button pressed, if so enter program condition (inside if statement)
  if(digitalRead(buttonPin2) == HIGH) 
  {
    stepper.setCurrentPosition(0); 
}
}

The AccelStepper library is much more comprehensive and I suggest you use it.

The usual way to get to the home position is with a function like this pseudo code

void gotToHome() {
  homeTriggered = digitalRead(homeSwitchPin) 
  while (homeTriggered == HIGH) {  // assumes LOW when pressed
     move a step towards home
     homeTriggered = digitalRead(homeSwitchPin)
  }
  currentPosition = 0;
}

...R Stepper Motor Basics Simple Stepper Code

Thanks a lot Robin,
Yeah, I was heading in that direction with the Accel library. I was putting together some code that you helped someone else with actually before I saw your post lol!

Jeff