O'Reilly logo

Building Smart LEGO MINDSTORMS EV3 Robots by Kyle Markland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Nesting the switches

The first switch will check the status of the color sensor, which is used to activate hungry mode. Add a switch block and set it to Color Sensor | Compare | Color and verify that port 3 is selected. Then, define the set of colors as [1; 2; 3; 4; 5; 6; 7;]. This is every color that the EV3 color sensor can detect (black, blue, green, yellow, red, white, and brown, respectively). This means that whenever a LEGO brick of any color is placed into Grunt's mouth, the switch returns true and hungry mode automatically activates. Note that no color (ID 0) is excluded. That is because if no color is detected, the switch will return false and the program will check the next sensor:

The code for the operating mode that corresponds ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required