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
If both the Set and Reset are false, the latch value remains unchanged. Note that a TRUE Reset overrides a TRUE Set but does not reset that parameter. Each parameter is reset individually. This function resets its parameters after they evaluate to true. This is significant only for functions that 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.