Using the compare switch
We will program a turret fire case directly after the aiming code we just wrote. Drag out a switch block and set its mode to Infrared Sensor | Compare | Beacon Heading. This mode allows us to set a desired beacon heading value. The EV3 will check the current sensor reading and compare it to the value we set here. The compare switch block is great because it combines three steps into a single block: it reads the sensor, compares its value to the desired target, then decides which case to execute based on whether the sensor value matches the target. In our specific example, if IR 2 measures a beacon heading of exactly zero, the EV3 will run the true case. Otherwise, it will run the false case.
We will set zero as our ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access