AccelStepper multistepper

Please help. when i try one function one by one in the loop then it does exactly what i wanted but when i put all the functions in loop then it doesn’t work from top to bottom thoroughly.steppers starts doing weird movements and different speed.
Please note. i’m self educated any very little knowledge about it.
A car can go to the point as steps given to the both stepper motors.
straight ,left turn,right turn and uturn
if the button is pressed,both stepper stops (pause) (while going straight or ,left turn or ,right turn or uturn ) and completes the steps after releasing the button

 //#include <avr/power.h>
#include <AccelStepper.h>
#include <MultiStepper.h>
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define STEPPER1_DIR_PIN 49
#define STEPPER1_STEP_PIN 47
// The 2 stepper pins
#define STEPPER2_DIR_PIN 53
#define STEPPER2_STEP_PIN 51

const int buttonPin = 10;
int buttonState = 1;
// Define some steppers and the pins the will use
AccelStepper stepper1(AccelStepper::DRIVER, STEPPER1_STEP_PIN, STEPPER1_DIR_PIN);
AccelStepper stepper2(AccelStepper::DRIVER, STEPPER2_STEP_PIN, STEPPER2_DIR_PIN);
MultiStepper steppers;

boolean oneTimeAction = false;
boolean motorMayRun = true;
boolean motorRunning = true;

void setup() {
pinMode(buttonPin, INPUT_PULLUP);

 //stepper1.setMaxSpeed(1600.0);stepper1.setAcceleration(800.0);
 //stepper2.setMaxSpeed(1600.0);stepper2.setAcceleration(1600.0);

 // Then give them to MultiStepper to manage
 steppers.addStepper(stepper1);
 steppers.addStepper(stepper2);
}
void loop() {
wayPoint1();
}



void wayPoint1() {
buttonState = digitalRead(buttonPin);

stepper1.moveTo(3200);//200steps *16
stepper2.moveTo(3200);
if (buttonState == LOW) {
     stepper1.stop();
     stepper2.stop();
   stepper1.disableOutputs();
   stepper2.disableOutputs();
   motorRunning = false;
   delay(1000);    
   }
   else {
       stepper1.setMaxSpeed(2000);
       stepper2.setMaxSpeed(2000);
       stepper1.setAcceleration(600.0);
       stepper2.setAcceleration(600.0);
       stepper1.moveTo(3200);
       stepper2.moveTo(3200);
       
       motorMayRun = true;
           stepper1.run();
           stepper2.run();
   

delay(1000);
        stepper1.setMaxSpeed(2000);
       stepper2.setMaxSpeed(2000);
       stepper1.setAcceleration(600.0);
       stepper2.setAcceleration(600.0);

       stepper1.moveTo(9600);
       stepper2.moveTo(9600);
           stepper1.run();
           stepper2.run();
 
}
} 
void turn90right() {
buttonState = digitalRead(buttonPin);

stepper1.moveTo(9600);//200steps *16
stepper2.moveTo(3200);
if (buttonState == LOW) {
     stepper1.stop();
     stepper2.stop();
   stepper1.disableOutputs();
   stepper2.disableOutputs();
   motorRunning = false;
   delay(1000);    
   }
   else {
       stepper1.setMaxSpeed(1600.0);stepper1.setAcceleration(1600.0);
       stepper2.setMaxSpeed(800);stepper2.setAcceleration(800);
       stepper1.moveTo(9600);
       stepper2.moveTo(3200);
       motorMayRun = true;
   }
   stepper1.run();
   stepper2.run();
  
} 

void goStreight() {
buttonState = digitalRead(buttonPin);

stepper1.moveTo(96000);//200steps *16
stepper2.moveTo(96000);
if (buttonState == LOW) {
     stepper1.stop();
     stepper2.stop();
   stepper1.disableOutputs();
   stepper2.disableOutputs();
   motorRunning = false;
   delay(1000);    
   }
   else {
       stepper1.setMaxSpeed(1600.0);stepper1.setAcceleration(1600.0);
       stepper2.setMaxSpeed(1600.0);stepper2.setAcceleration(1600.0);
       stepper1.moveTo(96000);
       stepper2.moveTo(96000);
       motorMayRun = true;
   }
   stepper1.run();
   stepper2.run();
  
} 

void uturnCCW() {
buttonState = digitalRead(buttonPin);
stepper1.moveTo(1800);//200steps *16
stepper2.moveTo(-1800);

   if (buttonState == LOW) {
   stepper1.stop();
   stepper2.stop();
   stepper1.disableOutputs();
   stepper2.disableOutputs();
   motorRunning = false;
   delay(1000);    
   }
   else {
       stepper1.setMaxSpeed(400.0);stepper1.setAcceleration(400.0);
       stepper2.setMaxSpeed(400.0);stepper2.setAcceleration(400.0);
       stepper1.moveTo(1800);
       stepper2.moveTo(-1800);
       motorMayRun = true;
   }
   stepper1.run();
   stepper2.run();
  
}

(Good attempt on the Code tags - next time, click the </> button, and paste your code inside the box that opens - Moderator)

Put Serial.print statements at various sections of your code and see if it gets that far. If you are not careful this can lock up your arduino in a serial flood. With each print statement put a delay of a few seconds. Always put one in the setup code that way you can get unlocked with a reset and programming the blink program into it. When you copy code it is best if you understand what your copying, it makes things much easier. You might spend some time with the Arduino tutorials and several pieces of data available for it.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.