Detecting Colors#

Detecting Colors

This tutorial walks you through using the Eye Sensor to detect a color, using a Green Disk as an example. By the end, you’ll have a project that prints a message once green is detected.

  1. Make sure your robot has an Eye Sensor connected. See Configuring Devices if you haven’t added one yet.

  2. Attach a set eye light block below the when started block. This helps the Eye Sensor detect colors more clearly.

The set eye light block, below when started.#
    when started :: hat events
        set eye light [on v]
  1. Attach a wait until block below it.

An empty wait until block, below set eye light.#
    when started :: hat events
        set eye light [on v]
        wait until <>
  1. Drag the Eye Sensor’s eye detects color Boolean block into the wait until block’s condition slot.

The eye detects color block added to the condition.#
    when started :: hat events
        set eye light [on v]
        wait until <eye detects [red v]?>
  1. Change the color parameter to green.

Screenshot of the project, with the eye detects color block's dropdown open, showing red, green, and blue options, and green selected.
  1. Attach a print block below the wait until block.

The print block, below wait until.#
    when started :: hat events
        set eye light [on v]
        wait until <eye detects [green v]?>
        print [VEXcode] ▶
  1. Change its text to Green detected!.

Screenshot of the finished project, with the print block's text set to Green detected!.
  1. Make sure your robot is connected to VEXcode. See Connecting to Your Robot if it isn’t connected yet.

Screenshot of the VEXcode GO toolbar, showing the Connect button in a Connected state.
  1. Select Start to run the project.

Screenshot of the VEXcode GO toolbar, with the Start button highlighted.
  1. Hold a Green Disk in front of the Eye Sensor. Once it’s detected, Green detected! will print to the Console.