Overview
IfThen compares input values to a set number or text, and outputs one of two values depending on the comparison result. This makes it easy to test to see if a sensor or other input value matches your criteria, and then cause some action to occur.
For example, you can set IfThen to make a comparison of “> 200”. If input sensor values are greater than 200, the widget could output 180 to move a servo all the way to the right. If it doesn’t, then the widget could output 0, moving a servo all the way to the left.
In a text example, you can set IfThen to make a comparison of “contains” “right,up” where if text coming from the speech recognizing widget SpeechIn contains a either the word “right” or “up” the output will tell a servo to move to the 180 position.
Features
- Numbers: Near Equal “~=”, defines a range
If you want an input number within a range instead of just greater or less than, use the “~=” comparison. With the ~= comparison, any number within a range, centered around the comparison value, will be a match. - Numbers: Greater Than “>”, Less Than “<”
The Greater Than “>” and Less Than “<” comparisons simply compare the input value to the set value. For “>” if the input is more than the set value, the right hand output value is sent, otherwise (i.e. input less than or equal to the set value) the left value is sent. For “<” if the input value is lower than the set value, the right hand output is sent, otherwise the left value is sent. - Text: “equals”, input text matches completely
When processing text, the input text matches the set comparison text exactly (ignoring case and with leading and trailing spaces removed). - Text: “contains”, input text contains a part that matches
A match is made if any part of the input text matches the comparison text. If you want to test for multiple comparisons then separate each possible match by a comma. For example, if the comparison text is set to “right, up” then any input phrase that contains the word “right” or “up” will result in a match. - Text: “part”, input text matches any part
A match is made if the input text matches exactly any part of the comparison text. For example, if the comparison text is set to “my favorite is the red balloon over there” and the input text is “red balloon” there will be a match. “my favorite” input will also match. - Wait true, wait false, for a delayed reaction
The wait true and wait false options are useful when you want something to react only when an incoming value has met your IfThen criteria for a certain amount of time. For example, if you are using a proximity sensor to make a sound when someone steps near, you could use a wait true time of 2000 msecs to make sure the person is staying in the right place for more than two seconds. Similarly, if you wanted the same sound to keep going even if the person steps away from the sensor, you can set the wait false time to say, 20,000, so the sound has a full 20 seconds to play out.