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

Programming the false case

We can now write some programming inside of the switch. We will start with the false case because it is simpler. This case will run if IR 2 does not see a beacon. If there is no nearby beacon, we simply want the robot to stop and wait until one is present.

Add three motor blocks into the bottom case of the switch. Each of these will stop the corresponding motor. The first block is a medium motor block. Set its mode to Off and set its port to A. This will halt the medium motor in port A, which controls the firing of the turret.

The second motor block will be a move tank block, which simultaneously controls the two drive motors. Set the mode of this block to Off as well. This will stop the robot's driving if no beacon is present. By default, the block controls the EV3 large motors in port B + C. These ports are correct, so there is no need to change it.

Add one more medium motor block with its mode set to Off. This time, be sure to set this block to port D. This will stop the turret from pivoting if no beacon is present.