Looking at the code I see so many problems and enough errors that I wouldn't work on it if it was for my project.
void otoac()
{
long duration, distance;
int distanceR = 0;
int distanceL = 0;
delay(40);
if(distance<=20)
{
Right there, distance is created as a long variable. The value when created will be whatever was left on the stack before, and then the code compares that to 20.... you didn't see that?
Every line, every command, every last number, letter or symbol in code COUNTS.
That is why to start with the simple, there is less to figure out every bit of!
Putting a loop in the otoac() function will only break the code more. The problem is in the serial input control part. Whatever key you press only gets acted upon one time per press.
Key commands only get done with a new char available(). What you want is that when no new key is pressed, the last command runs.
This might work but really that code is horrendous!
void loop(){
if(Serial.available() > 0){
command = Serial.read(); // does not check to make sure only a correct key was entered
}
Stop(); // why is this here? to "fix" a bug or just make the robot jerk about more?
switch(command){
case 'F':
forward();
break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
case 'G':
onsol();
break;
case 'I':
onsag();
break;
case 'H':
arkasag();
break;
case 'J':
arkasol();
break;
case 'W':
onac();
break;
case 'w':
onkapa();
break;
case 'X':
otoac();
break;
case 'x':
otokapa();
break;
}
}