Hi, how to make the 2 stepper motor (28byj-48) rotate at the same time step by step?
I use 2 stepper motor 28BYJ-48 and want to rotate forward at same time (CW n CCW) but at some step (about 50 degree rotation). The flow begin when I push 'On' a push button and it suppose to light up the LED and also make the stepper rotate. HOWEVER, the stepper keep making full rotation and not step by step. Any idea?
I already make some coding, and it working(stepper rotate, LED light up, On/Off push button) but not what I planned it to work. Everything are okay EXCEPT for rotating step by step,
#include <AccelStepper.h>
//some define,variable here//
int ledState = LOW;
int motorEnabled = 0;
boolean buttonState = LOW;
boolean previousButtonState = LOW;
void setup() /****** SETUP: RUNS ONCE ******/
{ stepper1.setMaxSpeed(2000.0);
stepper1.setAcceleration(8000.0);
stepper1.setSpeed(1000);
stepper2.setMaxSpeed(2000.0);
stepper2.setAcceleration(8000.0);
stepper2.setSpeed(1000);
// Set for push button and LED
pinMode(buttonPin, INPUT); // set push button as input
pinMode(ledPin, OUTPUT); // set LED as output
} //--(end setup )---
void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
buttonState = digitalRead(buttonPin);
if(previousButtonState != buttonState && buttonState == HIGH){
motorEnabled = !motorEnabled;
}
if(motorEnabled == 1){
digitalWrite(ledPin, HIGH);
stepper1.move(500); // rotate about 50 degree CW
stepper2.move(-500); // rotate about 50 degree CCW
}
else{
digitalWrite(ledPin, LOW);
stepper1.stop();
stepper2.stop();
}
stepper1.run();
stepper2.run();
previousButtonState = buttonState;
digitalWrite(ledPin, ledState);
}