Setting Delay Amount Via Serial Monitor

I’m wanting to control a set of pan/tilt servos controlled via a joy stick where the speed (Delay between the steps) can be adjusted through the serial monitor. I’ve got everything working as it should except I don’t know how to make the delay accept the data from the serial monitor.
Here is the code I’ve got so far.

#include <Servo.h>           //include servo library

Servo servo1;                // creating servo object
Servo servo2;
int joystick_x = A1;              // joystick x direction pin                                          
int joystick_y = A0;              // joystick y direction pin                                         
int pos_x;                   // declaring variable to stroe horizontal value
int pos_y;                   // declaring variable to stroe vertical value
int servo1_pos=90;          // storing servo position
int servo2_pos=90;
int servoSpeed;
int serialData = 0;
int data = 0;

//Serial Stuffs
char rx_byte = 0;
String rx_str = "";
boolean not_number = false;
int result;
//End Serial Stuffs

void setup ( ) {
Serial.println("Enter Servo Speed.");
Serial.begin(9600);
  servo1.attach (8);          // servo 1 attached pin
  servo2.attach (9);          // servo 1 attached pin
  servo1.write (servo1_pos);           
  servo2.write (servo2_pos);
  pinMode (joystick_x, INPUT);
  pinMode (joystick_y, INPUT);
}

void loop ( ) {
pos_x = analogRead (joystick_x);  
pos_y = analogRead (joystick_y);                      

if (pos_x < 300) {           //if the horizontal value from joystick is less than 300
  if (servo1_pos < 10) {     //first servo moves right
  } else {
    servo1_pos = servo1_pos - 1; 
    servo1.write ( servo1_pos ); 
    delay(rx_str); 
  }} 
checkSerial;
if (pos_x > 700) {          //if the horizontal value from joystick is greater than 700
  if (servo1_pos > 180) {     //first servo moves left
  } else {
    servo1_pos = servo1_pos + 1;
    servo1.write ( servo1_pos );
    delay(rx_str);
  }}
checkSerial;
if (pos_y > 700) {        //if the vertical value from joystick is less than 300
  if (servo2_pos < 10) {  //second servo moves right
  } else { 
    servo2_pos = servo2_pos - 1; 
    servo2.write ( servo2_pos ); 
    delay(rx_str);
  }}
checkSerial;
if (pos_y < 300) {
  if (servo2_pos > 180) {    
  } else {
    servo2_pos = servo2_pos + 1;
    servo2.write(servo2_pos);
    delay(rx_str);
  }}
checkSerial;
}

void checkSerial() {
  if (Serial.available() > 0) {    // is a character available?
    rx_byte = Serial.read();       // get the character
    
    if ((rx_byte >= '0') && (rx_byte <= '9')) {
      rx_str += rx_byte;
    }
    else if (rx_byte == '\n') {
      // end of string
      if (not_number) {
        Serial.println("Not a number");
      }
      else {
        Serial.println(rx_str);
      }
      not_number = false;         // reset flag
      rx_str = "";                // clear the string for reuse
    }
    else {
      // non-number character received
      not_number = true;    // flag a non-number
    }}
    }
checkSerial;

That is not a function call.

checkSerial();

THAT is a function call.

After doing a bit more digging I found what I needed to be able to convert the string to an int and got the code working how I needed it.

I’ll post the working code here in case anyone else needs it.

#include <Servo.h>           //include servo library

Servo servo1;                // creating servo object
Servo servo2;
int joystick_x = A1;              // joystick x direction pin                                          
int joystick_y = A0;              // joystick y direction pin                                         
int pos_x;                   // declaring variable to store horizontal value
int pos_y;                   // declaring variable to store vertical value
int servo1_pos=90;          // storing servo position
int servo2_pos=90;
int servoSpeed;
int serialData = 0;
int data = 0;

//Serial Stuffs
char rx_byte = 0;
String rx_str = "";
boolean not_number = false;
int result;
//End Serial Stuffs

void setup ( ) {
Serial.println("Enter Servo Speed.");
Serial.begin(9600);
  servo1.attach (8);          // servo 1 attached pin
  servo2.attach (9);          // servo 2 attached pin
  servo1.write (servo1_pos);           
  servo2.write (servo2_pos);
  pinMode (joystick_x, INPUT);
  pinMode (joystick_y, INPUT);
  servoSpeed = 5;
}

void loop ( ) {
  if (Serial.available() > 0) {    //Checks if a number was sent.
    checkSerial();
    }
    
pos_x = analogRead (joystick_x);  
pos_y = analogRead (joystick_y);                      

if (pos_x < 300) {           //if the horizontal value from joystick is less than 300
  if (servo1_pos < 10) {     //first servo moves right
  } else {
    servo1_pos = servo1_pos - 1; 
    servo1.write ( servo1_pos ); 
    delay(servoSpeed); 
  }} 
if (pos_x > 700) {          //if the horizontal value from joystick is greater than 700
  if (servo1_pos > 180) {     //first servo moves left
  } else {
    servo1_pos = servo1_pos + 1;
    servo1.write ( servo1_pos );
    delay(servoSpeed);
  }}
if (pos_y > 700) {        //if the vertical value from joystick is less than 300
  if (servo2_pos < 10) {  //second servo moves right
  } else { 
    servo2_pos = servo2_pos - 1; 
    servo2.write ( servo2_pos ); 
    delay(servoSpeed);
  }}
if (pos_y < 300) {
  if (servo2_pos > 180) {    
  } else {
    servo2_pos = servo2_pos + 1;
    servo2.write(servo2_pos);
    delay(servoSpeed);
  }}}



/*Serial Commands*/
void checkSerial() {
    rx_byte = Serial.read();       // get the character
    
    if ((rx_byte >= '0') && (rx_byte <= '9')) {
      rx_str += rx_byte;
    } else if (rx_byte == '\n') {
      // end of string
      
      if (not_number) {
        Serial.println("Not a number");
      } else {
        servoSpeed = rx_str.toInt();
        Serial.print("Servo Speed: ");
        Serial.println(servoSpeed);
        Serial.println("");
        }
      
      not_number = false;         // reset flag
      rx_str = "";                // clear the string for reuse
    } else {    // non-number character received
      not_number = true;    // flag a non-number
    }}

Edit: I did change up how the serial information was called due to delay issues with running the rest of the command. now everything works at the same speed as if there was no serial command and the speed was just all hard coded.

Also, thanks johnwasser for catching that on the function call for me.