Latch

(Engine-Level Function)

Description Latch On or Off. This function allows a transient change of a variable to be captured. Its return value is determined by the rules listed in the comments section.
Returns Boolean
Usage Steady State only.
Function Groups Variable
Related to: Toggle | MatchKeys | TimeOut | Intgr | RTimeOut
Format: Latch(Set, Reset)
Parameters  
Set  
Required. Any numeric expression. When true (i.e. not equal to 0), the latch is set.
Reset  
Required. Any numeric expression. When true (i.e. not equal to 0), the latch is reset.
Comments This function starts in a state with its return value being a valid 0 (false). The change in values is governed by the following rules

Set

Reset

Old Value

New Value

FALSE

FALSE

FALSE

FALSE

FALSE

FALSE

TRUE

TRUE

Either

TRUE

Either

FALSE

TRUE

FALSE

Either

TRUE

Invalid

TRUE

Either

FALSE

Either

Invalid

Either

Invalid

If both the Set and Reset are false, the latch value remains unchanged. Note that a true Reset overrides a true Set.

This function resets its parameters after they evaluate to true. This is significant only for functions which can be reset, such as MatchKeys, TimeOut, Intgr and RTimeOut.

Example:

motorOn = Latch(MatchKeys(1,"1") { Set the var with a "1" },
                MatchKeys(1,"0") { Reset the var with a "0" });

This controls the variable motorOn from the keyboard. MotorOn initially starts as 0. When 1 is pressed on the keyboard, the latch is set and motorOn becomes 1. When 0 is pressed on the keyboard, the latch is reset and motorOn becomes 0.

Latching and Resetting Functions