Manual and automatic mode

Gester1989:
It was this simple btw. while(dugme==1)

void otoac()

{
long duration, distance;
while(dugme==1)
{
int distanceR = 0;
int distanceL =  0;
delay(40);
if(distance<=24)
{
moveStop();
delay(100);
moveBackward();
delay(300);
moveStop();
delay(200);
distanceR = lookRight();
delay(200);
distanceL = lookLeft();
delay(200);
if(distanceR>=distanceL)
{
  turnRight();
  moveStop();
}else
{
  turnLeft();
  moveStop();
}
}else
{
moveForward();
}
distance = readPing();
}
}




But how will i get out of the loop when i touch 'x':


void otokapa()
{
  dugme=0;
  motor1.setSpeed(0);
  motor2.run(RELEASE); //turn motor1 off
  motor2.setSpeed(0);
  motor2.run(RELEASE); //turn motor2 off
}

We all know how simple it is. But what you dont know is that you didnt want help. You wanted us to do it for you. There is a difference. Learn coding first and try doing this after. You are trying to speak a language that you dont know anything about. Coding is not using somebody elses code. It is building your own that can tell a machine what to do. Just learn the language before trying to speak.