Look at the original code. Before it reads any serial data, it checks to see that there is something to read.
Look at the new code. It assumes that there is serial data to read. That is a piss poor assumption. 99.9% of the time, it is likely to be wrong.
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
// delay 10 milliseconds to allow serial update time
delay(10);
Rubbish. By the time you get finished sending out 13 bytes for every one you read, the serial buffer is going to have overflowed. Get rid of the stupid delay().
if (incomingByte == 105){
M_forward();
delay(25);
}
What do you need to send to receive a 105?
if (incomingByte == 'i'){
M_forward();
}
What do you need to send to receive a 'i'?
Why write cryptic code? Why are you welded to the stupid delay() function? If you don't want to do something different for a while, DON'T SEND ANYTHING!
Put some responsibility for proper control on the user. Quit overusing delay().
delay(25);
Another useless delay().
void ask_pin_F() //
{
myservo.write(90);
digitalWrite(outputPin, LOW); //
delayMicroseconds(2);
digitalWrite(outputPin, HIGH); //
delayMicroseconds(10);
digitalWrite(outputPin, LOW); //
float Fdistance = pulseIn(inputPin, HIGH); //
Fdistance= Fdistance/5.8/10; //
Serial.print("F distance:"); //
Serial.println(Fdistance); //
Fspeedd = Fdistance; //
}
What is with all the annoying empty comments?
I give up. I'm going to quit before one of us gets too irritated.