With delay(100) I can assure you that you're not getting 10 packets per second. Maybe 9.99, maybe slower. The code below uses a better way to send exactly 10 packets per second (well, within the limitation of accuracy on the Arduino's resonator which will drift by a few parts per million.)
While working on that code, I also stopped it overrruning the 15-character buffer.
Remember that Serial data has no built-in 'start'. You never know if you've received the start or middle or end of a message unless you include that in the message itself. It looks like you are expecting messages which contain either a single 'S' or 4 numbers separated by commas. What if you only got 3 numbers? How does your code know to wait? What if you got the last 3 numbers from the previous message and the next character is an 'S'?
My modifications to your code don't cope with all of those what-if's. Without seeing the full format of all the message types you're sending, I can't make any meaningful guesses.
The use of big-S String is unnecessary. There are small-s string functions that do the same thing. I did not entirely remove the String processing, just to keep this example simple.
I'm not clear on what getData() does. I don't know if you want to run that only 10 times per second.
void loop() {
const unsigned long TransmitInterval = 10000; //milliseconds - send out our data at this interval (10 times per second)
const int BufferLength = 15;
int blueToothLength;
int incomingSerialDataIndex = 0; // Stores the next 'empty space' in the array
char incomingSerialData[BufferLength];
while(blueToothSerial.available()) {
incomingSerialData[incomingSerialDataIndex] = blueToothSerial.read();
incomingSerialDataIndex++; // Ensure the next byte is added in the next position
if(incomingSerialDataIndex >= BufferLength) incomingSerialDataIndex = 0; //if we got too many characters, throw them all away and start again
incomingSerialData[incomingSerialDataIndex] = '\0';
}
if (Serial.available()){ //check if there's any data sent from the local serial terminal, you can add the other applications here
}
if(bluetoothMessageIsComplete(incomingSerialData, incomingSerialDataIndex))) {
//we got a complete message, according to some rules applied in the function that you have to write
//maybe you just need a specific number of characters or you need to see a carriage-return at the end of the string?
//Serial.println(blueToothData);
blueToothLength = incomingSerialDataIndex;
if (blueToothLength == 1) {
if (incomingSerialData[0] == 'S') {
blueToothData = '0';
//Serial.println("Stopped");
stopMotors();
}
} else {
//the only other 'complete' message we can get is the one with the 4 motor-control numbers
String blueToothData = incomingSerialData;
FL = splitSerial(blueToothData, ',', 0).toInt();
FR = splitSerial(blueToothData, ',', 1).toInt();
RL = splitSerial(blueToothData, ',', 2).toInt();
RR = splitSerial(blueToothData, ',', 3).toInt();
}
} //else the bluetooth message isn't complete yet
//always run the motor-control function as often as possible
//This may need to check limit switches or other motor parameters and it
//can't afford to wait hundreds of milliseconds before responding
//to those inputs.
MotorControl(FL, FR, RL, RR);
getData(); //MorganS: I have no idea what this does. Is this supposed to run on the 10 per second schedule?
//Is it time to transmit the data on the 10 per second schedule?
if(millis() - lastTransmitTime > TransmitInterval) {
transmitData();
while(millis()-lastTransmitTime > TransmitInterval) lastTransmitTime += TransmitInterval; //skip any missed transmissions
}
}