Serial Printing Data and Running Motors HELP

Hi.

To do something like that, you could use non-blocking delays like you mentioned. An alternative option that might be easier (since your delays are all multiples of 25ms) could be to make a function that loops some number of times, printing every 25ms. Then you could pass the function the number of times you want it to loop as an argument (or how long you want the delay to be) and use that instead of delay(). For example:

void printDelay(int loopCycles)
{

  for(loopCycles>0; loopCycles--)
  {
    Serial.print("Time: ");
    Serial.println(millis());
    delay(25);
  }
  return;
}

Note the timing probably won’t be exact since each line takes some time to execute. With this function, your code would look something like this:

// TURN RIGHT
    digitalWrite(M1, LOW);    //RIGHT MOTOR REVERSE
    digitalWrite(M2, HIGH);   //LEFT MOTOR FORWARD    
    analogWrite(E1, 150);     //RIGHT MOTOR PWM
    analogWrite(E2, 150);     //LEFT MOTOR PWM
    printDelay(2);  	   // 50/25=2

// STOP
    digitalWrite(M1, LOW);    //STOP
    digitalWrite(M2, LOW);    //STOP
    analogWrite(E1, 0);        //STOP
    analogWrite(E2, 0);       //STOP
    printDelay(40); 	// 1000/25 = 40

// and so on

Is there a reason you moved away from using the for loop method from your previous thread? Adding a serial print inside of that for loop and changing the delay to 25ms should also work.

Claire