Programming the false case

We will program the false case for this switch first because it is very straightforward. This case executes when the US sensor does not see an obstacle within 20 centimeters of its current position. There are no nearby obstacles, so the Omnilander does not need to take any action to avoid a collision. Therefore, the robot can simply continue driving forward.

In the false case of the US sensor switch, simply place a move tank block. Set its mode to On and set the power level to -75 for both drive motors. This will keep the robot driving in a straight line until the US sensor sees a nearby obstacle:

Get Building Smart LEGO MINDSTORMS EV3 Robots now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.