Jump to content
C4 Forums | Control4

Using Delay in Programming


Recommended Posts

Just a simple question about using programming delay.  Should I be using short amounts of delay between each programming command line? (say 250ms) or what is recommended?  I can see I would program a delay if something needed a few seconds to turn on or activate. I'm just wondering if I should be using delay all the time - does it help in commands working better?

Link to comment
Share on other sites


1 hour ago, bcinstaller said:

Just a simple question about using programming delay.  Should I be using short amounts of delay between each programming command line? (say 250ms) or what is recommended?  I can see I would program a delay if something needed a few seconds to turn on or activate. I'm just wondering if I should be using delay all the time - does it help in commands working better?

in the beginning for me, ~5 years - it was suggested to me by my dealer at the time to use 250 ms delays for anything super important just as an added safe guard a command would not get skipped over.  especially he said when doing text/push notifications/emails, etc.  that said I do have a ton of 250ms delays in my program but plenty of spaces without it out.  And even still, with and without delays, I have had lines of code skipped over in 5 years so not sure what to make of using the delay or not.  I've had code with delays miss triggers it seems as often as non delayed code.

Link to comment
Share on other sites

You should not really need delays in code.

To add a delay so a line is not skipped is not really understanding how it works.
Lines of code are queued and executed in order.
A code should not be 'skipped' over as such, if the result is not achieved, it is generally because of other factors.

Of course there will be exceptions - but if you need to use a delay - think carefully about what you are trying to achieve - can this be done another way?

If you are programming an action and then relying on that action being complete prior to further programming - then you are probably putting some of your coding in the wrong place...

ie: 
When room motionsensor senses motion:
   Turn on Light ABC
   If Light ABC is ON
       Set TOP LED on Light ABC to RED

Should be extracted out to two commands:

When room motionsensor senses motion:
   Turn on Light ABC

When Light ABC State Changes:
   If Light ABC is ON
       Set TOP LED on Light ABC to RED

Link to comment
Share on other sites

  • 2 weeks later...

you should try and not use delays unless the programming you want is getting unintended results. If you need a longer than 5 second delay you should use a timer instead as if the programming could be activated multiple times you might end up with a 10 second plus delay rather than just 5 seconds.

also a lot of the commands for devices have the delay baked into the driver so the system would be automatically delaying the correct amount of time to make sure everything responds correctly.

Link to comment
Share on other sites

  • 2 weeks later...
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.