Jump to content
Sign in to follow this  
Atom74

Library stepper.h

Recommended Posts

Hey guys,

I´m using a stepper motor in half step mode. In half step my motor has 400 steps. I wanna make it move one step at time with short pauses between each movement (2,5s). Also, after it completes the 400 steps it should start moving on the opposite direction. I´m using the library stepper.h but I´m having some doubts about it, this is my code at the moment:

 

#include <Stepper.h>

int x = 1; // step
int z = 0;
int w = -1;

const int stepsPerRevolution = 400; // number of steps in half step mode
Stepper myStepper(stepsPerRevolution, 8,9,10,11);

void setup() {
  myStepper.setSpeed(60); // 60 rpm
}

void loop() {
    myStepper.step(x);
    delay(2500); // pause between each step 2,5s
    x++;
    if(x==stepsPerRevolution) z=1; // when 400 steps then move in the opposite direction
   
    while(z){
      myStepper.step(-w);
      delay(2500);
      w--;
      if(w==-stepsPerRevolution) z=0 && x=1;
    }
   }
}

I don´t know if it is configure correctly. Should I use stepsPerRevolution = 200 (number of steps in full step mode) with x increasing in 0.5 by time? Also, can I use myStepper.step that way?  Thank you!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...