Within the software, you have a small conditional block called the SWITCH block. The SWITCH block tests for 1 or more conditions, based on the type of sensor or input/output you select from the drop-down menu.

Left, you drag and drop the SWITCH block onto the desktop. I'll place a MOVE block later and this will automatically push the SWITCH block to the right.














  This is the SWITCH block initially placed. It defaults to the Touch Sensor, indicated by the small hand pointing and touching a button. 


Inside the first vertical bar, you'll see a small icon near the top, indicating the TSensor has been pressed. Another small icon near the bottom shows the TSensor button being released. These are the two conditions that will determine what action the SWITCH block will take.


The SWITCH block can be configured for different sensors and various inputs.

The image below shows the drop-down menu and the possible selections for the sensors/inputs for the block.



The image below shows the configuration controls for the SWITCH block.  It defaults to port 1 because the Touch Sensor is the default sensor for the block.  Also notice I have turned off "Flat View" and the SWITCH block now has two tab-buttons along the top that have to be selected to see either the Pressed or Released conditions.

For the Pressed condition, I have placed a MOVE block.  It is set to a power level of 51 (half) and is supposed to move Motors B and C forward for 1 second, then brake.

Below, I have dropped in another MOVE block.  The SWITCH block automatically shifts to the right to create space for the new block.  I then dropped in a SOUND block.  The SOUND block is configured to play at half-volume (50) the wave file "Have a Nice Day".  This is occur if the button is not pressed when the SWITCH conditions are tested.

What this small program does is have the motors run for a set period of time (the initial MOVE block) and then test the condition of the Touch sensor.  If it is pressed (maybe it's bumped against a wall or object), the Pressed condition will trigger and motors B and C will reverse direction for 1 second (notice the first MOVE block has the down arrow and the 2nd MOVE block has the up arrow).  If the Touch sensor is not pressed, it will simply trigger the sound file... I can then put additional blocks after the SWITCH block to tell the bot what to do next.

Below is the configuration of the first MOVE block.  I tell it to spin motors B and C for 10 rotations and then brake.