TechTip: Bit Sequencing Using a Macro on Weintek HMI

In this TechTip, we’ll build on something we’ve looked at previously, and that’s For-Next loops.

In this example what we’re looking to do is sequence 8 bits in the HMI (LB-10-17) with a time delay – an application of this might be if you’re looking to perform several bit-triggered data transfers.

First off we’ll declare the variables…

macro_command main()
// Declare variables
bool bit // bit is a boolean (bool)
short loop // loop value – short (16bit)
short time=500 // time – short (16bit) = 500mS

Then we’ll do our loop – in this case, 10-17…

for loop=10 to 17 // loop has value 10 – 17 – we’ll use “loop” to set the address of the LB
bit = 1 // turn bit ON
SetData(bit, “Local HMI”, LB, loop, 1) // Set the HMI bit LB “loop” ON
bit = 0 // turn bit OFF
DELAY(time) // wait for delay of time (500mS)
SetData(bit, “Local HMI”, LB, loop, 1) // Set the HMI bit LB “loop” OFF
next loop // loop again & increment loop
end macro_command

A demo project is available to download here.