This TechTip is about using For/Next loops to ramp up and down a value on a Weintek HMI. The macro is using local word LW 100 as the output, the time in mS between steps is set by “time” (LW 101), the value to increment/decrement by is variable “IncDecValue” (LW 102) and the number of iterations is “steps” (LW 103). The Macro: macro_command main() short value = 0 // “value” is a short (16bit) – this has been zeroed – just in case! short IncDecValue // change the increment/decrement value here short i // i is a short to be used as the loop iteration counter short steps // steps is a short the number of for/next loop iterations short time // This is the time in mS used by DELAY GetData(time, “Local HMI”, LW, 101, 1) // Get the value for DELAY time GetData(IncDecValue, “Local HMI”, LW, 102, 1) // Get the value for the increment/decrement GetData(steps, “Local HMI”, LW, 103, 1) // Get the number of steps for i = 1 to steps // loop from 1 to value of “steps” value = value + IncDecValue // add IncDecValue to “value” SetData(value, “Local HMI”, LW, 100, 1) // put “value” into local word LW100 DELAY(time) // delay for the number of mS set in “time” next i // do the loop DELAY(time) // delay before decrementing for i = 1 to steps value = value – IncDecValue // as above but minus instead of plus SetData(value, “Local HMI”, LW, 100, 1) DELAY(time) next i end macro_command A demo project can be downloaded from here. You can run this using the simulator in EasyBuilder Pro.
For more information on TechTip: Ramp Up and Down a Value Using a Macro On Weintek HMI talk to Lamonde Automation Ltd