The LEGO® MINDSTORMS® EV3 Discovery Book

Page 21

Figure 9-1: The ButtonMenu program. The Wait block is configured in Brick Buttons – Compare – Brick Buttons mode, and the Switch block is in Brick Buttons – Measure – Brick Buttons mode.

Next, a Switch block (in Brick Buttons – Measure mode) determines which button is being pressed, and the robot plays the requested sound. After the Wait block completes, the Switch block runs so quickly that the button is still pressed by the time the Switch checks the button state, even if you release it right away.

using the rotation sensor When you tell the robot to move forward for three rotations with the Move Steering block, the vehicle knows when to stop moving because the Rotation Sensor in each EV3 motor tells the EV3 how much it has turned. The program can also tell you how fast a motor is currently turning by measuring how fast the motor position changes. You can use Wait, Loop, and Switch blocks in Motor Rotation mode to measure motor position (Degrees mode or Rotations mode) and motor speed (Current Power mode).

98 Chapter 9

motor position The motor position tells you how much a motor has turned since you started the program. Use the Port View app on the EV3 brick, navigate to motor B or C, and rotate the motors with your hands to see the sensor values change. When you first start Port View (or your own program), the sensor value is 0. The value becomes positive when you rotate a motor forward; it becomes negative if you turn it backward past 0, as shown in Figure 9-2. For example, if you rotate the motor forward by 90 degrees and then backward for one rotation (360 degrees), the motor should report a position of −270 degrees. You can use the position measurement to create a program that plays a sound if you turn one wheel 180 degrees forward by hand, as shown in Figure 9-3. A Wait block in Motor Rotation – Compare – Degrees mode waits until the Rotation Sensor value is greater than or equal to (≥) 180 degrees. Because these sensors are built into the EV3 motors, they are always connected to output ports (you use the motor on output port B in this program).


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.