program help !!!

new to this world of c code i have done tons of looking around but i cant find how to step by step run 2 steppers at the same time or step only one at a time useong the afmotor shield ive tryed the while statement on the ladyada example but counld only get one at a time not both at once if i wanted to drive straight useing a skid steer bot

code i tryed

//
// Control both Stepper motors at the same time with different speeds
// and accelerations.
// Requires the AFMotor library (https://github.com/adafruit/Adafruit-Motor-Shield-library)

#include <AccelStepper.h>
#include <AFMotor.h>

// two stepper motors one on each port
AF_Stepper motor1(48, 1);
AF_Stepper motor2(48, 2);

// you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
// wrappers for the first motor!
void forwardstep1() {  
  motor1.onestep(FORWARD, INTERLEAVE);
}
void backwardstep1() {  
  motor1.onestep(BACKWARD, INTERLEAVE);
}
// wrappers for the second motor!
void forwardstep2() {  
  motor2.onestep(FORWARD, INTERLEAVE);
}
void backwardstep2() {  
  motor2.onestep(BACKWARD, INTERLEAVE);
}

// Motor shield has two motor ports, now we'll wrap them in an AccelStepper object
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);

void setup()
{  
    stepper1.setMaxSpeed(20.0);
    stepper1.setAcceleration(100.0);

    stepper2.setMaxSpeed(20.0);
    stepper2.setAcceleration(100.0);
      stepper1.run();
    stepper2.run();

    
      stepper1.runToNewPosition(80);
    stepper2.runToNewPosition(50);
    stepper1.runToNewPosition(120);
    stepper2.runToNewPosition(120);

    while (steps--) {
    motor1.step(150, BACKWARD, INTERLEAVE); 
    motor2.step(150, BACKWARD, INTERLEAVE); 
}


void loop()
{
  motor1.release();
  motor2.release();
  delay(9000);
  delay(3000);
}

Moderator edit: CODE TAGS

      stepper1.runToNewPosition(80);
    stepper2.runToNewPosition(50);
    stepper1.runToNewPosition(120);
    stepper2.runToNewPosition(120);

These functions block. That is stepper1.runToNewPosition() does not return until the stepper gets to the new position. Then the second stepper can start to move.

If you want them to move "at the same time" you need a different library. If you can live with them taking smaller steps, you need to use a for loop, and step each motor ONE STEP AT A TIME in the loop.

ok i tryed this same problem tho can not step to motors at same time :frowning:

#include <AFMotor.h>


AF_Stepper motor1(48, 1);
AF_Stepper motor2(48, 2);


void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Stepper test!");

  motor1.setSpeed(100);  // 10 rpm   
  motor1.release(); 
  motor2.setSpeed(100);  // 10 rpm   
  motor2.release(); 

 
  delay(5000);
  motor1.setSpeed(180);
  motor1.step(200, FORWARD, DOUBLE); 
  motor1.release(); 
  motor2.release(); 
  motor2.step(200, FORWARD, DOUBLE); 

  motor1.release(); 
  motor2.release(); 


  motor1.setSpeed(200);
  motor1.step(88, FORWARD, DOUBLE); 
  motor2.step(88, BACKWARD, DOUBLE); 

  motor1.release(); 
  motor2.release(); 

  delay(5000);
  motor1.setSpeed(50);
  motor2.step(28, FORWARD, DOUBLE); 
  motor2.step(28, BACKWARD, DOUBLE); 
 
  motor1.release(); 
  motor2.release(); 

  delay(5000);
  motor1.setSpeed(50);
  motor1.step(130, FORWARD, DOUBLE); 
  motor1.step(28, BACKWARD, DOUBLE); 

  motor1.release(); 
  motor2.release(); 

  delay(5000);
  motor1.setSpeed(120);
  motor2.step(50, FORWARD, DOUBLE); 
  motor2.step(28, BACKWARD, DOUBLE); 

  motor1.release();
  delay(1000);
}

void loop() {



  motor1.release(); 
  motor2.release(); 



}

Moderator edit: CODE TAGS
soo reading what was said above i cant find another libary that will fix this ?

would i be able to step both motors with an easy driver or run 2 easy driver those seem to be popular ?

or should i attempt to build my oh h brige for this its just ive seen other people run this afmotor driver with a track style rc car and it worked for them not sure why im haveing so much trubble thanks for any help in the matter !

ok i tryed this same problem tho can not step to motors at same time

Because you are STILL telling each motor to take a large number of steps. Use a for loop to make each motor step ONE step, as you've been told TWICE now.

OK OVER ALL stepping each motor only 1 step then the other and blocking is going to leave me with 1000 lines of code to make my robot move 2 feet so the for loop as you put it will fix that right ? i have not used a for loop soo not sure how i would apply it could some one give me and example of cupple move ments on with the for loop like 2 at once then one in revers and other forward ? then if i see how the loop should be set up i could probly figuer it out from there i just dont know how to set up all the camands yet and c code does not make sence to me reading it … jermmy blums you tube has helped me thus far … smart guy props to you all … ! thanks for any help and im sorry i dident know what you ment the first time @ Pual

1 step then the other and blocking is going to leave me with 1000 lines of code to make my robot move 2 feet

Or one line of code, repeated.

Is there a better language for you in the International section?

Have a look at this thread discussing the same problem: