Additional Programming Highlights

 

Yes or No Touch:

 The Yes or No block is one of the Stack Decision Makers. This block controls the flow of the program based on input from the touch sensor. The block is always a part of a stack, and therefore, it is carried out when its turn comes as blocks in the stack execute. You can set the block to check for one of two states, pressed or released. (Note that the “click” event is not available here.)

© The LEGO Group

© The LEGO Group

 

 

 

The main point here is that this block is carried out once. When the block is reached, the program asks, “Is the sensor pressed? Yes or No?” If the answer is “Yes,”  the stack attached to Yes will set off. If the answer is “No,” the stack attached to No will set off.

 

 

 

Here the question is “Is the sensor released? Yes or No?”  If the answer is “Yes,” the stack will run. If the answer is “No,” nothing will happen because there are no command blocks in the No branch.

 

 

 

Tech Guide

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Return to Top

How Stack Decision Maker Touch is Different from Sensor Watcher: In some aspects, the Stack Decision Maker block Yes or No is very similar to a Sensor Watcher. Both watch for the state of a sensor. They are different, however, in some import ways: While the Sensor Watcher monitors the sensor on an ongoing basis (in very short intervals), the Stack Decision Maker Yes or No block looks for input once, when its turn comes.

 

As a result, timing the input to coincide with the execution of the Yes or No block is critical, while timing is less important for the Sensor Watcher. (It keeps looking.) Another important distinction is that each Sensor Watcher watches for a single event, responding to a single condition (e.g., if pressed). The stack triggers only when the condition is true. The Stack Decision Maker Yes or No is prepared to trigger one stack if the condition is true and another stack if the condition is false. It triggers actions both when the answer is yes and when the answer is no.

 

Here the  stack will trigger just once. The program will not go back to monitor the sensor because it runs top-down. Note that here you must press and hold the touch sensor as you press the Run button, or it would be too late for the Yes or No block to receive that input.

 

© The LEGO Group

© The LEGO Group

One of the stacks will trigger each time the sensor is pressed. The other will trigger each time the sensor is released

Return to Top

Setting the range for light Stack Decision Makers:

Setting light sensor conditions for the Stack Decision Makers is much like that for the Sensor Watchers with one exception. The Repeat While and Yes or No Decision Makers can’t be set to recognize a blink.

Since all Stack Decision Makers look for input when their turn to execute comes, it is critically important that the Decision Maker block has a chance to receive and process incoming sensor input.

The following sequence of three programs illustrates that the timing of input is critical when working with Stack Decision Makers.

In the program NoChance1, the Yes or No Stack Decision Maker happens to be the first block in the stack. It will look for input as soon as the Run button is pressed. If a light is not flashed at the sensor at the same time as the Run button is pressed, the Decision Maker will direct the program to the No branch.

 

 

 

© The LEGO Group

In the program Chance, however, once the Run button is pressed, there are 3 seconds before the Yes or No Decision Maker’s turn comes. For the Decision Maker to choose the Yes branch, the sensor has to receive a bright light when the 3 seconds are up.

Practically, a user will start shining a light at the sensor before the time is up and continue to shine it for a bit longer while the Yes or No block carries out.

 

© The LEGO Group

The same will happen in the program NoChance2, because executing the On AC block happens instantaneously, and therefore doesn’t buy time.

 

 

 

 

 

 

© The LEGO Group

Transparency #6A illustrates the programs NoChance1, NoChance2, and Chance discussed above

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Tech Guide

 

Tech Guide

Close Window