Subroutines or My Blocks

In this section, we will program the robot to move forward until it encounters an unknown obstacle with the Touch Sensor and then attempt to steer around the obstacle. An obstacle such as a table or chair leg would be ideal. We will program the robot to take input from the brick buttons. The program we will initially write is inefficient and repetitive. It is actually a good example of how you shouldn't write a program. We will first simplify the code using the EV3 version of a subroutine or function that is called My Block. You can think of a My Block as a small program within a large program. It is called a My Block because it is a block that you create.

At the beginning, the robot will move forward until the Wait block ...

Get Learning LEGO MINDSTORMS EV3 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.