# Simple Timer Problem

## Recommended Posts

A little assistance required again to keep me going!

I am currently experimenting with timing functions to trigger pump and fan relays but am struggling to set multiple start criteria. For example, below i have an output triggered on the 11th minute when a DI is detected but if i wanted to trigger a pump on say 0, 15, 30 and 45 minute, how would I go about this. Or if half of my fans were only able to start on even or odd minutes. Obviously I w.ouold not need 30 individual lines with each number in I have tried putting a series of numbers and using the "or" command, but to no avail. Have been through the timing section in the manual and most of the posts on the forum without finding a solution, so i'm probably not looking for it in the right context, but anyway, a little push in the right direction please!

```While(1)
IF ((DI0_IN[0] &gt; 0) &amp;&amp; FormatDateTime("%M",sysTime()) == 11)
DO0_OUT = 1
ENDIF
delay(0.2)
endwhile```

Many thanks.

Mark

##### Share on other sites

Unfortunately, your technique in your script won't work well even as written. You loop 50 times a second (kind of fast for what you are doing), so if DIO_IN[0] > 0, that if() will evaluate to true for the entire minute, thus setting DO0_OUT to 1 some 3000 times! The best pattern for doing things at times is to use a variable to store the next time you want to do something. For example, every hour:

```private nexttime = floor(systime() / 3600) * 3600 + 3600
while(1)
waituntil(nexttime)
nexttime += 3600
if (DIO_IN[0] &gt; 0)
DO0_OUT = 1
endif
endwhile```

Another method is to use an event. For example, in your case, you could put this in the event code for DI0_IN:

if ((DI0_IN[0] > 0) && (DO0_OUT[0] != 1) && (FormatDateTime("%M",systime()) == 11))

DO0_OUT = 1

endif

Note that I check for DO0_OUT already being set to 1. The problem with this is that it will only execute when DI0_IN is read, and if that doesn't occur in the 11th minute, DO0_OUT won't get set.

As for doing it on the 15 minute, use the first script and use 900 instead of 3600. As for even or odd, use the modulus (%) to determine if the minute is even or odd:

odd:

FormatDateTime("%M",systime()) % 2 = 1

even:

FormatDateTime("%M",systime()) % 2 = 0

or better yet (much faster executing):

odd:

systime() % 120 >= 60

even:

systime() % 120 < 60

Truthfully, I only use formatdatetime() when I need to look for a transition in an event, or looking for something related to months (since months don't have even # of seconds in them and so its hard to use regular math on systime())

##### Share on other sites

• 9 months later...

Hi

i tried your script, that works at every hour after a hour of it starts .it's pretty good. i need something like this

method, the differance is

my squence have to work at the exact hour passing times. for example at 3 o'clock or 22 o'clock. sorry about

this question. my scripting haven't improve enough. may suggest something about it!

thank you..good day.