Skip to main content
Bumped by Community user
clarified title
Link
jsotola
  • 1.5k
  • 2
  • 12
  • 20

How to change the directioncount steps of a stepper motor with AccelStepper if I don't know the exact position?

Source Link

How to change the direction of a stepper motor with AccelStepper if I don't know the exact position?

I want to turn on my motor and count how many total rounds it has until my limit switch is switched on. After that, I want to count rounds counterclockwise until another limit switch is pushed. For this, I'm using AccelStepper and ezButton lib.

Here is my code:

      if ((limitSwitch_XV.getState() == LOW) && (limitSwitch_XE.getState() == LOW) && rightDirectionX) {
        while (1) {
          stepper1.step(-1);
          stageSizeX++;
        }
      }

But here I've got an error which says that I can't use int in step(): 'virtual void AccelStepper::step(long int)' is protected within this context stepper1.step(1);

So how can I count the steps and go step by step to the given direction until I reach the limit switch with AccelStepper?