Problem with Accelstepper library to change speeds.

Hi i am making a plotting machine and i want to interpret G-code to run some stepper motors. They need to run at the same time and at different speeds so i utilised the modified Accelstepper library for the stepper motors i am using(28byj-48). I always seem to get 1.00 as my stepper speed when i read it even though i read the variable i used to set the speed and it is not 1.00. This is preventing my motors from moving at different speeds. I have changed the speed in this way because the motors must finish the G-code command at the same time.
Here is my code.

#include <AccelStepper.h>
int xspd;
int yspd;
const int spd=60;
int n;
int x=10;
int y=10;
int l;
AccelStepper stepperY(5, 2, 3, 4, 5);
AccelStepper stepperX(5, 6, 7, 8, 9);
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
stepperX.setCurrentPosition(0);
stepperY.setCurrentPosition(0);
}


void loop() {
  // put your main code here, to run repeatedly:
if(Serial.available()>0){
if(Serial.peek()=='G'){
  Serial.read();
  n=Serial.parseInt();
Serial.println(n);
if(Serial.peek()=='X'){
  Serial.read();
  x=Serial.parseInt();
  
}
if(Serial.peek()=='Y'){
  Serial.read();
  y=Serial.parseInt();
  
}
 switch(n){
 
case 0:
if(stepperY.distanceToGo()== 0){
  if(y<x){
    yspd=(spd*y/x);
   Serial.println("yspd is ");
      Serial.println(yspd);

       stepperX.moveTo(x);
       stepperY.moveTo(y);
             
      stepperY.setSpeed(yspd);
      stepperX.setSpeed(spd);
//     stepperY.setSpeed(spd);
//     stepperX.setSpeed(spd);
    Serial.println("y speed is ");
   Serial.println(stepperY.speed());
    Serial.println("x speed is ");
   Serial.println(   stepperX.speed());
   }else if(x<y){
   xspd=(spd*x/y);
Serial.println("xspd is ");
         Serial.println(xspd);

         stepperX.moveTo(x);
         stepperY.moveTo(y);
            stepperX.setSpeed(xspd);
         stepperY.setSpeed(spd);
        Serial.println("y speed is ");
        Serial.println(stepperY.speed());
         Serial.println("x speed is ");
        Serial.println(stepperX.speed());
//     stepperY.setSpeed(spd);
//         stepperX.setSpeed(spd);
   }
   
}
while(stepperY.distanceToGo()> 0){
stepperX.runSpeed ();
stepperY.runSpeed();
Serial.print("x=");
Serial.println(stepperX.distanceToGo());
Serial.print("y=");
Serial.println(stepperY.distanceToGo());
}
break;

}
}
}
x=0;
y=0;
}

I hope someone can help.
Thank you.

Sorry i forgot to add my serial monitor results. This is what i get from the serial monitor if i enter G0X700Y500.
0
yspd is
42
y speed is
1.00
x speed is
1.00
x=699
y=499
x=699
y=499
x=699
y=499
x=699
y=499
x=699
y=499
x=699
y=499
x=699
y=499
x=699
y=499
x=699
y=498
x=698
y=498
x=698
y=498
x=698
y=498
x=698
y=498
x=698
y=498
x=698
y=498
x=698
y=498
x=698
y=498
x=698
y=498
etc...

raa442:
I have changed the speed in this way because the motors must finish the G-code command at the same time.

The AccelStepper library is specifically NOT suited to that requirement. There is a MultiStepper variant of the library for that but it cannot use acceleration - I don’t know if that would be a problem.

To make it easier for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to a text editor.

…R
Stepper Motor Basics
Simple Stepper Code

Thank you for showing me this library. It will be very usefull for a prototype version of my code, however i am not sure as to how i can use it to draw curves because it does not support accelaration or decelaration. are you sure it is not possible to use the accelstepper library to change constant speeds during the loop part of the code.

raa442:
however i am not sure as to how i can use it to draw curves because it does not support accelaration or decelaration.

Drawing curves and acceleration are two completely different things.

You say you are using 28BYJ stepper motors (and, presumably, ULN2003 drivers). They make programming a bit more difficult than if you were using a bipolar stepper motor and a driver like the Pololu A4988 that just needs step and direction inputs.

However it would be straightforward to create a moveOneStep() and a setDirection() function that would work with your motors and then any code written for an A4988 could be easily adapted to your system. Such as the examples in this Simple Stepper Code

If you were to do that then you would not get much (if any) advantage from the AccelStepper library. And it would also be straightforward to write your own acceleration code. I posted an example in Reply #7 in this other Thread.

...R