user24174: Here is my objective:
If the value of EMGv is at or above 900, start moving the motors left. The motors should continue to move left for a maximum of one second, provided EMGv stays at or above 900. If during this time EMGv goes below 900, the motors should move right for one second. Then the motors should stop. At any time after this should EMGv go above 900 again, the process should repeat.
In simpler terms, the project is a robotic hand, wired to an EMG circuit. When the EMG signal gets above 900 the hand should close by the motors all turning left for one second and when the signal goes below 900 the hand should open by the motors turning right for one second.
Here is my loop atm when move(motor #, speed, direction (1 for left, 0 for right)) is the function to move the motors and stop() stops all motors
void loop(){

  unsigned long starttime; //time limit for hand movement
  int EMGv = analogRead(EMG);
  starttime=millis();
  while(EMGv >= 900){
    if (millis()-starttime < 1000) //limit on 1000ms
    {
    move(0, 255, 1); //motor 1, full speed, left
    move(1, 255, 1); //motor 2, full speed, left
    move(2, 255, 1); //motor 3, full speed, left
    move(3, 255, 1); //motor 4, full speed, left
    move(4, 255, 1); //motor 5, full speed, left  
    } else {
      stop();
    }
  }
}


user16085: I suspect you would do well to first write (in English) the exact set of rules you want it to follow -- don't worry about the code to begin with - get it clear in your head what you want the code to do.  (If this is already clear to you, then just write it :-) )
Here's what I think you might mean -- although it's not exactly what you wrote.
If EMG is at or above 900, start moving the motors left.  The motors should continue to move left for a maximum of one second, provided EMG stays at or above 900.  If during this time EMG goes below 900, the motors should move right for one second.  Then the motors should stop.
Once you have that, turning it into code looks well within your ability, judging by the code you've posted.  Here's my attempt - note that it'll only be correct if I have correctly stated your desired rules.  (And if I've correctly guessed how the move API works - I guess it starts the motor moving, that you need to cancel it to stop it moving.  Please say if this is wrong.)
I've used LEFT and RIGHT instead of 1 and whatever, for clarity.
void loop(){
  // If EMG is at or above 900
  int EMGv = analogRead(EMG);
  if (EMGv >= 900) 
  {
    unsigned long starttime = millis();

    // Start the motors moving left
    move(0, 255, LEFT); //motor 1, full speed, left
    ...and the other motors...

    // Continue for a maximum of one second, and while EMG stays at or above 900
    while ( (millis()-starttime < 1000) && ((EMGv = analogRead(EMG)) >= 900)) {
      // Just wait
      delay(1);
    }

    // If during this time EMG goes below one second...
    if (EMGv < 900) {
      // ...the motors should move right for one second
      move(0, 255, RIGHT); //motor 1, full speed, right
      ...and the other motors...
    }

    // Then the motors should stop.
    move(0, 0, LEFT); //motor 1, stop, left
    ...and the other motors...
  }

// More stuff here, otherwise it will immediately go round the loop again and start moving again
}


24174: <p>Here is my objective:</p>

<p>If the value of <code>EMGv</code> is at or above 900, start moving the motors left. The motors should continue to move left for a maximum of one second, provided <code>EMGv</code> stays at or above 900. If during this time <code>EMGv</code> goes below 900, the motors should move right for one second. Then the motors should stop. At any time after this should <code>EMGv</code> go above 900 again, the process should repeat.</p>

<p>In simpler terms, the project is a robotic hand, wired to an EMG circuit. When the EMG signal gets above 900 the hand should close by the motors all turning left for one second and when the signal goes below 900 the hand should open by the motors turning right for one second.</p>

<p>Here is my loop atm when <code>move(motor #, speed, direction (1 for left, 0 for right))</code> is the function to move the motors and <code>stop()</code> stops all motors</p>

<pre><code>void loop(){

  unsigned long starttime; //time limit for hand movement
  int EMGv = analogRead(EMG);
  starttime=millis();
  while(EMGv &gt;= 900){
    if (millis()-starttime &lt; 1000) //limit on 1000ms
    {
    move(0, 255, 1); //motor 1, full speed, left
    move(1, 255, 1); //motor 2, full speed, left
    move(2, 255, 1); //motor 3, full speed, left
    move(3, 255, 1); //motor 4, full speed, left
    move(4, 255, 1); //motor 5, full speed, left  
    } else {
      stop();
    }
  }
}
</code></pre>
 16085: <p>I suspect you would do well to first write (in English) the <em>exact</em> set of rules you want it to follow -- don't worry about the code to begin with - get it clear in your head what you want the code to do.  (If this is already clear to you, then just write it :-) )</p>

<p>Here's what I think you might mean -- although it's not exactly what you wrote.</p>

<p><em>If EMG is at or above 900, start moving the motors left.  The motors should continue to move left for a maximum of one second, provided EMG stays at or above 900.  If during this time EMG goes below 900, the motors should move right for one second.  Then the motors should stop.</em></p>

<p>Once you have that, turning it into code looks well within your ability, judging by the code you've posted.  Here's my attempt - note that it'll only be correct if I have correctly stated your desired rules.  (And if I've correctly guessed how the <code>move</code> API works - I guess it starts the motor moving, that you need to cancel it to stop it moving.  Please say if this is wrong.)</p>

<p>I've used LEFT and RIGHT instead of 1 and <em>whatever</em>, for clarity.</p>

<pre><code>void loop(){
  // If EMG is at or above 900
  int EMGv = analogRead(EMG);
  if (EMGv &gt;= 900) 
  {
    unsigned long starttime = millis();

    // Start the motors moving left
    move(0, 255, LEFT); //motor 1, full speed, left
    ...and the other motors...

    // Continue for a maximum of one second, and while EMG stays at or above 900
    while ( (millis()-starttime &lt; 1000) &amp;&amp; ((EMGv = analogRead(EMG)) &gt;= 900)) {
      // Just wait
      delay(1);
    }

    // If during this time EMG goes below one second...
    if (EMGv &lt; 900) {
      // ...the motors should move right for one second
      move(0, 255, RIGHT); //motor 1, full speed, right
      ...and the other motors...
    }

    // Then the motors should stop.
    move(0, 0, LEFT); //motor 1, stop, left
    ...and the other motors...
  }

// More stuff here, otherwise it will immediately go round the loop again and start moving again
}
</code></pre>
