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
# 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)
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:
// True when minutes divided by 15 has no remainder and seconds are zero.
getMinute(now()) % 15 = 0 && getSecond(now()) < 1
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