# REV Color Sensor V3

This sensor is emits light and then analyzes the reflected light that it sees. It is capable of measuring:

* raw distance up to 10cm (but most effective under 2cm)
* Alpha&#x20;
* Hue&#x20;
* Red&#x20;
* Blue&#x20;
* Green

&#x20;

Full Guide from REV Robotics: <https://docs.revrobotics.com/color-sensor/>&#x20;

Color Sensor Class Documentation: <http://ftctechnh.github.io/ftc_app/doc/javadoc/index.html>

Distance Sensor Class Documentation: <http://ftctechnh.github.io/ftc_app/doc/javadoc/index.html>&#x20;

Supporting Images:

<figure><img src="https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FixvVd0dEQ8CiEPaflmgN%2Fimage3?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FsgUa2blJ8mACI38ndTgK%2Fimage1?alt=media" alt=""><figcaption></figcaption></figure>

### Useful code:

Add your sensor object with the rest of your robot objects:

<figure><img src="https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FDCogMyKsMSgAxHyNUMhA%2Fimage5?alt=media" alt=""><figcaption></figcaption></figure>

Hardware map it!:

<figure><img src="https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2F0vRGoJQIovpRmj6Krb3T%2Fimage2?alt=media" alt=""><figcaption></figcaption></figure>

Add some code like this to your main loop to read the values on your sensor:

<figure><img src="https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FQsPTrjSRdPTDmmQVATrY%2Fimage4?alt=media" alt=""><figcaption></figcaption></figure>

Try something like this to drive until your sensor sees a red line:

```
while( color.red() < 100){
    backLeft.setPower(.5);
    backRight.setPower(.5);
    frontLeft.setPower(.5);
    frontRight.setPower(.5);
}
backLeft.setPower(0);
backRight.setPower(0);
frontLeft.setPower(0);
frontRight.setPower(0);
```

\*Note, this code is not intended to work right off the bat… this is just an idea of how you could use a color sensor to control your robot!\*
