[SOLVED]Unable to send more data trough Serial Monitor

Hi, I recently finished my first pcb (a stepper controller) and i wanted to get it to its limits, but to do that, i needed an Arduino. I'm using an Arduino nano. I made my own "fancy" code to do what i want (precisely increment or decrement the frequency of an specific pin), but i got to a "limit". I cant send more data via the serial monitor, it just gets stuck. The way that my code works, is that you input an operator (+ or -) followed by the amount that you want to decrease or increase the period of the actual frequency. Until the 10ms mark you increase or decrease in mS, and lower than 10mS, you start working with uS.
Going back to my problem, i tried using Serial.flush(); and it worked a bit (i was able to input more data), but it worked once, and never again. Here is my code:

#define CLK 2

void aDelay();
void TrabjData();
void SerialDisplay();

int T = 200;
String oDATA;
char sDATA;
bool sts;


void setup() {
  // put your setup code here, to run once:
  pinMode(CLK, OUTPUT);
  Serial.begin(115200);
  Serial.println("|PERIODO|  FREQ |       |");
  Serial.println("|ACTUAL | ACTUAL| ESCALA|");
  Serial.println("|   ^   |   ^   |   ^   |");
  Serial.println("|  T_A  |  F_A  |  ESC  |");
  SerialDisplay();

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(CLK, HIGH);
  aDelay();
  digitalWrite(CLK, LOW);
  aDelay();
  TrabjData();
}

void aDelay() {
  if (sts == 0) {
    delay(T / 2);
  } else {
    delayMicroseconds(T / 2);
  }
}

void TrabjData() {
  if (oDATA.charAt(0) == '+') {
    int mT = oDATA.toInt();
    T = T + mT;
    oDATA = "";
    if (T < 10 && sts == 0) {
      T = T * 1000;
      sts = 1;
    }
    if (T > 10000 && sts == 1) {
      T = T / 1000;
      sts = 0;
    }
    SerialDisplay();
  }
  if (oDATA.charAt(0) == '-') {
    int mT = oDATA.toInt();
    T = T + mT;
    oDATA = "";
    if (T < 10 && sts == 0) {
      T = T * 1000;
      sts = 1;
    }
    if (T > 10000 && sts == 1) {
      T = T / 1000;
      sts = 0;
    }
    SerialDisplay();
  }

}

void serialEvent() {
  while (Serial.available()) {
    char inDATA = (char)Serial.read();
    oDATA += inDATA;
  }
  Serial.flush();
}

void SerialDisplay() {
  Serial.print("|");
  Serial.print(T);
  if (sts == 0) {
    Serial.print("mS");
    Serial.print("  |");
    Serial.print(1000 / T);
    Serial.print("Hz");
    Serial.print("  |");
    Serial.println("mS  |");
  } else {
    Serial.print("uS");
    Serial.print("  |");
    Serial.print(1000000 / T);
    Serial.print("Hz");
    Serial.print("  |");
    Serial.println("uS  |");
  }
}

i learned a bit of arduino, but im no pro in C++, so, make any suggestions you want!

Regards

Serial.flush() does nothing to serial input. It just waits until any characters in the Serial output buffer have been sent.

The Arduino sketch can read bytes from the Serial buffer way faster than they arrive over the serial line. If the while() loop empties the buffer before the end of your message arrives you will receive only a partial message and act on it.

Perhaps you can use Serial.parseInt(). Not only does that accept positive and negative numbers, but it will also wait up to a second after the last digit it receives to make sure it has the whole message.

johnwasser:
Serial.flush() does nothing to serial input. It just waits until any characters in the Serial output buffer have been sent.

The Arduino sketch can read bytes from the Serial buffer way faster than they arrive over the serial line. If the while() loop empties the buffer before the end of your message arrives you will receive only a partial message and act on it.

Perhaps you can use Serial.parseInt(). Not only does that accept positive and negative numbers, but it will also wait up to a second after the last digit it receives to make sure it has the whole message.

Oh, i didnt know that Serial.flush() didnt wiped the buffer. Thats what my professor told me. Anyway, i tried Serial.parseInt() and it seems that the buffer wont get full anymore. The only tweak i had to do is to set the Serial.setTimeout()down to 1ms, to avoid the frequency to stop for 1 sec. Other than that, it worked! Thanks Jhon!