Pause loop until a task is complete

Hello
I am working on a project that takes input from Bluetooth module and then send those to the system. I want the system to ask for the first variable and only after it gets the first variable it should ask for the second variable.

What is happening write now is that it asks for the first variable and then when i enter the 1st variable it asks for the second variable only once and then it asks for the first variable again. If any of you could help me stop or pause the loop until a task is complete it would be really good.

This is my program

void setup() {

Serial.begin(9600);
pinMode(13,OUTPUT);// put your setup code here, to run once:

// put your main code here, to run repeatedly:

}

void loop()
{
int x1,y1;
Serial.println(" Enter x ");
if(Serial.available()>0)
{ x1=Serial.parseInt();
Serial.println("x is");
Serial.println(x1);
}
delay(1000);
if(x1>0)
{
Serial.println(" Enter y");
y1=Serial.parseInt();

if(Serial.available()>0)
{
Serial.println("y is");
Serial.println(y1);
Serial.print("\n");

}

delay(1000);
}

}

while (!first_input) {
   read_first_input();
}

while (!second_input) {
   read_second_input();
}

Sorry my dear friend.. but i don't understand your idea.
Actually i am new to these .. if you could give me clearer picture ..

Have a look at the simple user-input example in Planning and Implementing a Program

You need a variable that keeps track of the state of your system - for example is it waiting for inputA or inputB or none of them

...R

I finally got it

void setup() {

Serial.begin(9600);
// put your setup code here, to run once:

// put your main code here, to run repeatedly:

}

void loop()
{
int x1,y1;
Serial.println(" Enter x ");
if(Serial.available())
{ x1=Serial.parseInt();
Serial.println("x is");
Serial.println(x1);
}
delay(100);
if(x1>0)
{
line11: Serial.println(" Enter y");
delay(100);

if(Serial.available())
{ y1=Serial.parseInt();
Serial.println("y is");
Serial.println(y1);
Serial.print("\n");
delay(100);
}
else
{
goto line11;
delay(100);
}
}
delay(1000);
}

     goto line11;
            delay(100);

(retreats to bunker for the duration of the unpleasantness about to ensue)

TolpuddleSartre:
(retreats to bunker for the duration of the unpleasantness about to ensue)

May I join you?

You bring the wine and I'll bring the glasses :slight_smile:

...R

Hey
I am unable to send data from my android phone to arduino board via bluetooth. I have done it before to do the same with a different code and it worked fine. When i connect the module it blinks repeatedly
As soon as i connect my phone to the module and open the app its blinking pattern change. Like a delay then blinks twice, again delays for a while and blinks twice again and so it goes on until i exit from my app. When i exit it comes back to the previous blinking pattern

My code

void setup() {

Serial.begin(9600);
// put your setup code here, to run once:

// put your main code here, to run repeatedly:

}

void loop()
{
int x1,y1;
Serial.println(" Enter x ");
if(Serial.available())
{ x1=Serial.parseInt();
Serial.println("x is");
Serial.println(x1);
}
delay(100);
if(x1>0)
{
line11: Serial.println(" Enter y");
delay(100);

if(Serial.available())
{ y1=Serial.parseInt();
Serial.println("y is");
Serial.println(y1);
Serial.print("\n");
delay(100);
}
else
{
goto line11;
delay(100);
}
}
delay(1000);
}

The code works pretty well with the serial monitor alone.
I am not sure if the problem is with the hardware or code or with the app. If someone has an idea of whats going on please reply.

This seems to be the same code as in your other Thread.

I am suggesting to the Moderator to merge them. Double posting just wastes time.

...R