if statement if condition is met and do until condition is met

I have two separate inputs and what to do when the if statements match, however I want to just wait till the condition changes and restart the loop again I am having trouble with the code to wait. So basically if condition 1 is met I want to println(text); until this condition happens (jrx >= 700) then restart the loop by calling loop();

void loop() {
  int jrx = analogRead(A0);
  int mrx = analogRead(A5);
  
 Serial.print("Loop Start");
 digitalWrite(mptt, LOW);
 digitalWrite(jptt, LOW);
 
 delay(1000);
  if (jrx <= 700) {digitalWrite(mptt, HIGH);}
  if (mrx >= 700) {digitalWrite(jptt, HIGH);}
  if (jrx <= 700 && mrx >=700){Serial.println("No Activity");}
}

[ What happened to the code tags? Please fix your posting to use them. ]

I think (not sure) that your best course of action is to go and checkout the blinkWithoutDelay example to see how to handle delays without calling delay(), then see if that helps you achieve what you want.

brizey:
I have two separate inputs and what to do when the if statements match, however I want to just wait till the condition changes and restart the loop again I am having trouble with the code to wait. So basically if condition 1 is met I want to println(text); until this condition happens (jrx >= 700) then restart the loop by calling loop();

void loop() {

int jrx = analogRead(A0);
 int mrx = analogRead(A5);
 
Serial.print(“Loop Start”);
digitalWrite(mptt, LOW);
digitalWrite(jptt, LOW);

delay(1000);
 if (jrx <= 700) {digitalWrite(mptt, HIGH);}
 if (mrx >= 700) {digitalWrite(jptt, HIGH);}
 if (jrx <= 700 && mrx >=700){Serial.println(“No Activity”);}
}

I do not believe that calling loop() from loop is advisable. The Arduino would end up running a loop within another loop. I believe that it’s best to let the Adruino call loop from it’s main function only.

I believe that you will find a boolean flag a good choice. I call it, isActivity. Basically, everything inside the first if statement is executed if isAcivity is true. Otherwise it is skipped and the loops restarts testing jrx and mrx and then setting isActivity. I added another boolean such that the message NoActivity is printed only once.

Please note that I’m making some assumptions about the problem you’re having. This may not exactly match the solution you’re looking for. Still, I believe that using a boolean flag in the loop is probably the best way to look at solving this problem.

void loop() {
  static boolean isActivity = true;
  static boolean isWarningPrinted = false;
  int jrx = analogRead(A0);
  int mrx = analogRead(A5);
  
  isActivity = jrx > 700 || mrx < 700;
  
  if (!isActivity && !isWarningPrinted){
    Serial.println("No Activity");
    isWarningPrinted = true;
  }
  
 if(isActivity){ 
   Serial.print("Loop Start");
   digitalWrite(mptt, LOW);
   digitalWrite(jptt, LOW);
 
     if (jrx <= 700) {
      digitalWrite(mptt, HIGH);
    }
    if (mrx >= 700) {
      digitalWrite(jptt, HIGH);
    }
    isWarningPrinted = false;
 }
}

You almost solved your own question right in the title of this post. It's called do... while.

http://arduino.cc/en/Reference/DoWhile

See also the very closely related: http://arduino.cc/en/Reference/While

If you want to start the loop() function at the beginning again, just return; It will be called again immediately.