noDelay, explain the millis

hey, im looking into combinations of noDelay and serial writing. this is what i have going now.

// http://arduino.cc/forum/index.php?topic=74861.0
// http://arduino.cc/playground/Code/AvoidDelay

int bIntrvl = 100;
int bl_intrvl = 200;

unsigned long bTimer ,blTimer;

void setup() {
  Serial.begin(19200);
  Serial.println("init");
}

void loop() {
  beepLoop();

}
void beepLoop(){
  if(millis() - blTimer > bl_intrvl){
    beepNoDelay();
    blTimer = millis();
  }
}
void beepNoDelay(){
  if(millis() - bTimer > bIntrvl){  
    Serial.print("high   > ");
   Serial.println(millis() - bTimer);
  }
  if(millis() - bTimer > bIntrvl+100 ){  
    Serial.print("low   > ");
   Serial.println(millis() - bTimer);
    bTimer = millis();;
  }
}

i am getting this on the serial monitor. high > 205 low > 211

please help understand the 5ms and 11ms introduced. -is it the serial com taking those 5ms? yes, (almost) with 9600baud i get high > 209 low > 222 with 115200 high > 201 low > 202

i think ill stick to 115200 as its fast, but still would like to get some info.

-what are the implications? is it stopping my avr from digitalReading/writing , etc. is there any problem with faster baud rates? buffering too fast? i had problems with interfacing maxmsp with arduino, seems to get "stuck" at 11.5kb. what is the best strategy with working at high baud rates.

It is just that printing over serial (and in fact every statement ) takes time.

Better try the same code with >= iso >

furthermore you can optimize for speed by calculating millis() - bTimer only once…

// http://arduino.cc/forum/index.php?topic=74861.0
// http://arduino.cc/playground/Code/AvoidDelay

int bIntrvl = 100;
int bl_intrvl = 200;

unsigned long bTimer ,blTimer;

void setup() 
{
  Serial.begin(115200);
  Serial.println("init");
}

void loop()
{
  beepLoop();
}

void beepLoop()
{
  if (millis() - blTimer > bl_intrvl)
  {
    beepNoDelay();
    blTimer = millis();
  }
}

void beepNoDelay()
{
  unsigned long time = millis() - bTimer;

  if (time >= bIntrvl)
  {  
    Serial.print("high   > ");
    Serial.println(time);
  }
  if (time >= ( bIntrvl +100) )   // note that if the first fails this one will certainly fail...
  {  
    Serial.print("low   > ");
    Serial.println(time);
    bTimer = millis();
  }
}