Learn 4: Experiment With Color Sensing
6. Demo: Now with Color Sensor
Now let’s add some code that:
- senses a green marker
- turns the robot around by 180 degrees so that it can return the way it came.
We’ve written some template functions that you can use here.
These functions:
- read the color sensor (read_color_sensor( )),
- record the values read in container attributes for use by the data analysis graph,
- light both of the courier’s eyes up to show the color just read (record_color( )).
Add these lines just above the time.sleep(0.1) line
read_color_sensor()
record_color('both')
if var.color_name == ‘green’:
courier.turn_degrees(180)