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 ...

Get Building Smart LEGO MINDSTORMS EV3 Robots now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.