# Generate 0.5s and 0.25s pulse tag

**URL:** <https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391>\
**Category:** Ignition\
**Created:** [October 26, 2018, 5:51am UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391 "2018-10-26T05:51:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 26, 2018, 5:51am UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391/1 "2018-10-26T05:51:32Z")

</div>

Hi,

What is the most efficient way to generate a half and quarter second pulse for use in blinking animations on pages?  
I have two internal expression tags and have been using expressions with getMillis(now(5)), but this seems like it could be done more efficiently. Using this also results in periods where the bit remains higher for longer than it should.

I really wish that colour binding ‘blink’ properties would be synchronised ☹

Thanks

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [October 26, 2018, 8:44am UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391/2 "2018-10-26T08:44:16Z")

</div>

I would create 2 Boolean client tags:

```auto
flash_half
flash_quarter

```

These would be driven from a client timer script running at a fixed rate of 250mS:

```auto
flash_quarter = system.tag.read('[Client]flash_quarter').value
flash_half = system.tag.read('[Client]flash_half').value
if flash_quarter:
	system.tag.write('[Client]flash_quarter', 0)
else:
	system.tag.write('[Client]flash_quarter', 1)
	system.tag.write('[Client]flash_half', not flash_half)

```

I think you’ll find a quarter of a second is a bit fast for the animation to keep up. One second and half a second might be better values.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [October 26, 2018, 5:34pm UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391/3 "2018-10-26T17:34:39Z")

</div>

> [@Synchronized Animation/blinking](http://forum.inductiveautomation.com/t/synchronized-animation-blinking/7198/6):
>
> EDIT: fixed dead link. My take is a bit different-- as most of my takes seem to be. laughing : A Client folder called “Flash”. This folder contains a tag called RootValue, which is updated by a Client Timer script running at 125ms: value=system.tag.read("[Client]Flash/RootValue").value + 1 if value \> 15: value = 0 system.tag.write("[Client]Flash/RootValue", value) Then, added four more tags, each extracting a different bit from RootValue. Now I have four different bits with f…

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 29, 2018, 11:45pm UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391/4 "2018-10-29T23:45:43Z")

</div>

Thanks for the replies.

I ended up using client tags and a client script:

```auto
# Set this to the script execution time period in ms
timeInterval = 125
# Time to count up to in ms. This affects the times pulses that may be generated
counterPeriod = 2000

tag = "[Client]System/Pulses/125ms Counter"
counter = system.tag.read(tag).value

# Increment the 125ms counter tag if the time is within the counterPeriod time, otherwise reset to 0
if counter > (counterPeriod/timeInterval - 1):
	system.tag.write(tag, 0)
else:
	system.tag.write(tag, system.tag.read(tag).value + 1)

# Write the pulse values to the client tags
system.tag.write("[Client]System/Pulses/125ms", int(counter*timeInterval / 125) % 2)
system.tag.write("[Client]System/Pulses/250ms", int(counter*timeInterval / 250) % 2)
system.tag.write("[Client]System/Pulses/500ms", int(counter*timeInterval / 500) % 2)
system.tag.write("[Client]System/Pulses/750ms", int(counter*timeInterval / 750) % 2)
system.tag.write("[Client]System/Pulses/1000ms", int(counter*timeInterval / 1000) % 2)

```

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [October 30, 2018, 3:46am UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391/5 "2018-10-30T03:46:23Z")

</div>

You could also do this all without any python scripting.

1. Create a scan class that is your flash rate (If you want it on for 0.5s, off for 0.5s, make the scan class direct at 500ms)
2. Create an expression tag, lets call it flasher. Leave the expression blank.
3. Edit your tag, and add a script like

```auto
if(isNull({[~]Flasher}),False,!{[~]Flasher})

```

That should work just peachy.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 30, 2018, 3:48am UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391/6 "2018-10-30T03:48:43Z")

</div>

I wouldn’t have even thought of this, cheers!

---

<div class="post-metadata">

**Author:** ![alexm](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alexm](https://forum.inductiveautomation.com/u/alexm)\
**Post date:** [October 22, 2019, 10:16am UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391/7 "2019-10-22T10:16:50Z")

</div>

How would the script be if the flasher needs to go high for 1 second every 15 min of the hour?

So 10:00, 10:15,10:30,10:45,11:00 but 24/7

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [October 22, 2019, 4:13pm UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391/8 "2019-10-22T16:13:48Z")

</div>

In theory the expression below in an expression tag would give you a one second flash at the start of each quarter hour, but, depending on scan class speed, the flash may be a bit short or it may miss executions:

```java
// True when minutes divided by 15 has no remainder and seconds are zero.
getMinute(now()) % 15 = 0 && getSecond(now()) < 1

```

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [November 2, 2019, 2:12pm UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391/9 "2019-11-02T14:12:43Z")

</div>

Here’s an even simpler way to create a tag to drive flashing: create a client tag and set its expression to

```auto
toMillis(now(1000)) % 2000 < 1000

```

The value of this tag will toggle between 0 and 1 every second. You can play with the values if you want asymmetrical flashing.

---

<div class="post-metadata">

**Author:** ![alexm](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alexm](https://forum.inductiveautomation.com/u/alexm)\
**Post date:** [November 7, 2019, 2:39pm UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391/10 "2019-11-07T14:39:57Z")

</div>

if you could explain the script as well that would be much appreciated.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [November 7, 2019, 6:49pm UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391/11 "2019-11-07T18:49:08Z")

</div>

The expression gets the time now every 1000ms and converts it to total milliseconds. It then uses the modulus operator, %, with 2000 to effectively turn it into a 0-2000 value which upon reaching 2000 will loop back around to 0 and start again. \<1000 will then convert 0-2000 into 1-0 over 2000 ms, so 1 for 1s, 0 for 1s

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 7, 2019, 8:04pm UTC](https://forum.inductiveautomation.com/t/generate-0-5s-and-0-25s-pulse-tag/20391/12 "2019-11-07T20:04:03Z")

</div>

I like to use objectScript’s state variable, with the timing determined by the scan class:

```auto
objectScript("state.get('toggle', False)\nstate['toggle'] = not __retv")

```

If you want something other than a 50% duty cycle, say, one-third, I do this:

```auto
objectScript("state.get('step', 0)<1\nstate['step'] = (state.get('step', 0)+1) % 3")

```

(Well, I tend to put helpers in a shared script file, to which I pass the state dictionary…)
