Let's code the robot to avoid obstacles
Your LEGO BOOST kit's color sensor can detect six different colors: red, blue, green, yellow, black, and white. It can detect color from a maximum distance of 3 cm. Now, create the following setup before we start with the activities:
Let's get started.
Activity #1
Go forward until the robot senses a red pole and change the brick light to red. Let's first write an algorithm to reflect this:
- Move forward at 20% speed.
- Wait until red is sensed.
- Stop motor AB when red is sensed.
- Change the brick light color to red.
The sample code for this activity is as shown in the following figure:
Let's now write a similar code for the robot to execute when it senses the blue brick.
Activity #2
Program your robot to turn left whenever it senses blue...