halt one stepper until other has revolved once, then continue simultaneously
hi everyone,
i 2 motors following:
1. stepper1 , stepper2 turn simultanously 6400 steps
2. stepper1 stops until stepper2 has completed 3200 steps
3. stepper1 , stepper2 turn again simultaneously 6400 steps
4. stepper1 stops until stepper2 has completed 3200 steps
3. stepper1 , stepper2 turn again simultaneously 6400 steps.
all of should happen when send "1" serial communication. using accelstepper library (http://www.airspayce.com/mikem/arduino/accelstepper/).
my code far, including serial communication , other important chunks have stay in is below. how , have modify code? have insert if-loop in if (letter=='1') loop? have tried around different loops , commands have not been able figure out.
any advice appreciated!
thanks,
isa
}
i 2 motors following:
1. stepper1 , stepper2 turn simultanously 6400 steps
2. stepper1 stops until stepper2 has completed 3200 steps
3. stepper1 , stepper2 turn again simultaneously 6400 steps
4. stepper1 stops until stepper2 has completed 3200 steps
3. stepper1 , stepper2 turn again simultaneously 6400 steps.
all of should happen when send "1" serial communication. using accelstepper library (http://www.airspayce.com/mikem/arduino/accelstepper/).
my code far, including serial communication , other important chunks have stay in is below. how , have modify code? have insert if-loop in if (letter=='1') loop? have tried around different loops , commands have not been able figure out.
any advice appreciated!
thanks,
isa
code: [select]
#include <accelstepper.h>
// define 2 steppers , pins use
accelstepper stepper1(1, 9, 8);
accelstepper stepper2(1, 7, 6);
// define variable record when instruction arrived.
unsigned long instructiontime = 0;
void setup() {
serial.begin(9600);
stepper1.setmaxspeed(8000);
stepper2.setmaxspeed(8000);
stepper1.setacceleration(100000000);
stepper2.setacceleration(100000000);
}
void loop()
{
if (serial.available() > 0)
{
char letter = serial.read();
if (letter=='1')
{
stepper1.move(-6400);
stepper1.setspeed(3350);
stepper2.move(6400);
stepper2.setspeed(3350);
instructiontime = millis();
}
else if (letter=='2')
{
stepper1.move(-6400);
stepper1.setspeed(3350);
stepper2.move(6400);
stepper2.setspeed(3350);
instructiontime = millis()+500;
}
// run if either stepper1 or stepper2 has distance left go.
if (stepper1.distancetogo() != 0 || stepper2.distancetogo() != 0)
{
// run stepper1 regardless of time
stepper1.runspeedtoposition();
// run stepper2 if time more 500ms when the
// instruction received
if (millis() >= instructiontime)
{
stepper2.runspeedtoposition();
}
if (stepper1.distancetogo() == 0 && stepper2.distancetogo() == 0)
{
serial.print('x');
}
}
}
}
Arduino Forum > Using Arduino > Programming Questions > halt one stepper until other has revolved once, then continue simultaneously
arduino
Comments
Post a Comment