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.