Building Smart LEGO MINDSTORMS EV3 Robots
上QQ阅读APP看书,第一时间看更新

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 block. By default, its condition will be set to repeat infinitely. Since that is what we want, there is no need to change it! This will serve as the master loop; the rest of the robot's programming will go inside this loop. It makes the program repeat indefinitely until the user manually stops it using the button on the EV3 brick: