Posted on: 03/22/2015
We’ve added a new IfThen widget, which makes is easy to make decisions about the project behavior.
IfThen compares input values to a set number, and sends one of two values depending on the comparison result. This makes it easy to test to see if a sensor value matches your criteria, then cause some action to occur.
For example, you can set the IfThen with a comparison of “> 200”. If 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.
- 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.
- Wait true, wait false, 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.