Latch

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.

Format:                      Latch(Set, Reset)

Parameters:             Set    { Boolean }  { required }  { no default }

                                      Any numeric expression. If true (i.e. not equal to 0), the latch is set.

                                    Reset    { Boolean }  { required }  { no default }

                                      Any numeric expression. If 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.

See Also:

Toggle