Controlling Stepper Motor with Arduino Serial Monitor

Hi there, I am looking to control my stepper motor's speed with arduino's serial monitor, I am using UNO and Adafruit Motor Shield V2.3

There are 4 speed divided into 4 categories a, b, c and d, the idea is that when you press 'a' the stepper motor would rotate on the selected RPM, 'b' another RPM and so-on. Press 's' and motor would stop

Everything is fine when i press 'a'. However when I want to change to 'b' there isnt any response from the motor and it will continue rotating in 'a' setting.

Attached is my code for the above scenario. Please advice

Thank you

#include <Wire.h>
#include <Adafruit_MotorShield.h>

Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);


void setup() {
  Serial.begin(9600);     
  Serial.println("Stepper Test");

  AFMS.begin();  
  //AFMS.begin(1000); 
}

void loop() {

  char n;
  if (Serial.available() > 0)
   {
      int command = Serial.read();
   {

   if (command == 'a')
   {
    Serial.println("Setting Speed to 19.1 RPM");
    delay (1000);
      do
      {
        myMotor->setSpeed(19.1);
         myMotor->step(10000,FORWARD, DOUBLE);

      } while (Serial.available() == 0); 
      Serial.read();    
   } 
   else if (command == 'b')
   {
       Serial.println("Setting Speed to 38.2 RPM");
    delay (1000);
        myMotor->setSpeed(38.2);
        myMotor->step(10000,FORWARD, DOUBLE);
   }
   else if (command == 'c')
   {
    Serial.println("Setting Speed to 57.3 RPM");
    delay (1000);
    myMotor->setSpeed(57.3);
    myMotor->step(10000,FORWARD, DOUBLE);
   }
   else if (command == 'd')
   {
    Serial.println("Setting Speed to 76.4 RPM");
    delay (1000);
     myMotor->setSpeed(76.4);
    myMotor->step(10000,FORWARD, DOUBLE);
   }
 else if (command == 's')
   {
    myMotor->release();
  ;
   }
   }
}
}

b, c, and d don't have the do-while loop to repeat the motion until a character arrives. You should let loop() do the repeating and just change the speed when input arrives. Try this:

// #include <Wire.h>
#include <Adafruit_MotorShield.h>


Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 2);




void setup()
{
  Serial.begin(9600);
  Serial.println("Stepper Test");


  AFMS.begin();
  //AFMS.begin(1000);
}


void loop()
{
  static bool moving = false;


  if (moving)
    myMotor->step(200, FORWARD, DOUBLE); // One revolution


  if (Serial.available() > 0)
  {
    byte command = Serial.read();


    switch (command)
    {
      case 'a':
        Serial.println("Setting Speed to 19.1 RPM");
        delay (1000);
        myMotor->setSpeed(19.1);
        moving = true;
        break;


      case 'b':
        Serial.println("Setting Speed to 38.2 RPM");
        delay (1000);
        myMotor->setSpeed(38.2);
        moving = true;
        break;


      case 'c':
        Serial.println("Setting Speed to 57.3 RPM");
        delay (1000);
        myMotor->setSpeed(57.3);
        moving = true;
        break;


      case 'd':
        Serial.println("Setting Speed to 76.4 RPM");
        delay (1000);
        myMotor->setSpeed(76.4);
        moving = true;
        break;


      case 's': // Stop
        moving = false;
        break;
    }
  }
}