can we replace the delay by an if

can we replace the delay by an if condition

like:

delay(if...);

No, but you can do

if (someThing == true)
{
  delay(someTime);
}

I don't think so, but you could do it the other way round....

if (some condition or other is true) {
    delay(sometime);
}
// carry on....

EDIT.... as UKHB said.... 8)

yes
no

if (condition) delay(n)

better not to use delay at all - check the blink without delay example - it uses variables to keep track of time to act.

check the blink without delay example

Woah Rob! This guy's used up a year's question quota in 12 hours, don't encourage anything which will invite more.....

I jest, of course.... OP you're welcome to ask as many questions as you like but I suspect you will soon stop getting answers since what you really ought to be doing, is read the reference, work the examples and search the playground

Are you after control of the delay time only:

int delay_time;

if( condition ){
  delay_time = 1000;
}else{
  delay_time = 50;
}

delay( delay_time );

I suspect writing this is in vain, the OP will be onto the next thread soon.

I suspect writing this is in vain, the OP will be onto the next thread soon

:smiley:

I suspect records are tumbling...

delay (someCondition ? trueDelayTime : falseDelayTime);

AWOL:

delay (someCondition ? trueDelayTime : falseDelayTime);

THAT's going to spawn 5 more threads.....

AWOL:

delay (someCondition ? trueDelayTime : falseDelayTime);

I was holding back from posting that for the same reasons given by Jimbo above. Hell might as well just post:

  struct LongDelay{
    enum{ TIME = 1000 };
  };
  
  struct ShortDelay{
    enum{ TIME = 50 };
  };  
  
  template< bool flag, typename T, typename U >
    struct Select { typedef T Result; };
    
  template< typename T, typename U >
    struct Select<false, T, U> { typedef U Result; };
    
  
  delay( Select< condition, LongDelay, ShortDelay >::Result::TIME );

Oops, sorry, just looked at the posting history. :astonished: