Setting up the program

Before we start to write the program, we need to assign port numbers to both of the IR sensors. The program makes use of both of the IR sensors on the robot. The IR sensor that is mounted to the robot's chassis is plugged into port 1, so we will refer to this sensor as IR 1. The sensor mounted to the turret is plugged into port 2, so we will refer to that sensor as IR 2. It is imperative to remember this because the program identifies these sensors using their port numbers. We use the port numbers to tell the robot which sensor to check at any given time.

Now that we have established the numbers we will use to identify the sensors, we can start writing the program!

The first block we will add into our program is a loop ...

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.