Equation logic
Whens, ands, ors, but no ifs or buts...
Last updated
Whens, ands, ors, but no ifs or buts...
Last updated
The equation menu, shown in image I, has 4 options: logic, input, output, and sequence. Let's focus on the "logic" option. Logic is the connective tissue of most equations, determining how inputs and outputs are related. When you press on the logic icon in the equation menu, you get the logic menu, as shown in image II, with 5 options: "WHEN," "AND," "OR," "WHILE," & "OTHERWISE." Let's take a look at each type of statement.
WHEN statements: the most common logical form for equations, with the syntax: “When this happens, do this,” as shown in image III. By tapping “this happens,” you will open inputs, and by tapping “do this” you will open the outputs menu. Example (image IV): When button is pressed, set glow module to cyan aqua.
AND operator: The “and” here is added to a context, so that it can be added to a When statement, giving “When this happens and this happens, do this,” as shown in image V.
To clear up any confusion on the logical use of our "AND" operator, there are three possible logical types of “and” in our equations. Consider the following sentence:
"When the button is pressed and distance is less than 1500, turn glow to cyan aqua and relay module to on, and when force is greater than 1000, set servo to 180 degrees."
The first “and” here is the one that our “And” logical operator adds. The second one, which adds outputs, is simply done by pressing the blue "+" icon and selecting another output, and it is shown in the sentence view by a comma. The third “and,” the one that separates different logical statements entirely, is achieved by selecting another “when” and is represented by an ampersand (“&”) in our equation view. The above becomes: "When the button is pressed and distance is less than 1500, turn glow to cyan aqua, set relay to on, & when strength of force is greater than 1000, move to 180 degrees," as shown in image VI.
OR operator: "Or" plays the same role as “and” here in modifying the condition / context necessary for an action to occur, giving “When this happens or this happens, do this,” as shown in image VII.
WHILE statements: Similar to "When" statements, but act as an umbrella statement over certain when statements. In other words, any "When" statement that follows a "While" statement will only happen while the context in that while statement is true. Example (image IX): While distance is less than 1000, set move to 90 & When button is pressed, set glow to red. In this example, the button will not set the glow to red unless distance is less than 1000.
OTHERWISE operator: The "Otherwise" logic operator must follow a "When" statement - if you add one without a "When" statement, the "When" will be automatically added. The "Otherwise" statement subordinates one context to another, so that the second one will only happen if the first one is not true. You can make a chain of "Otherwise" statements to check for multiple contexts in a certain priority. Example (image XI): When distance is less than 1000, set glow to red Otherwise when button is pressed, set glow to bright green. In this example, the button press will only set the glow to green if the distance is greater than 1000. If both contexts are true, the first one will win and the glow module will be red.