> For the complete documentation index, see [llms.txt](https://help.trikset.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.trikset.com/en/trik/programming-code/object-brick/class-colorsensor.md).

# Class «colorSensor»

{% hint style="info" %}
This article is automatically translated from Russian by Google Translator.
{% endhint %}

The camera in color sensor mode.

| Method                                                                    | Description                                                                                                            |
| ------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| [init​](/en/trik/programming-code/object-brick/class-colorsensor.md#init) | Turns the camera on and initializes it in color sensor mode.                                                           |
| [read​](/en/trik/programming-code/object-brick/class-colorsensor.md#read) | Returns an array with the coordinates of the dominant color in the RGB color scale in the specified area of the frame. |
| [stop](/en/trik/programming-code/object-brick/class-colorsensor.md#stop)  | Turns off the camera and stops the sensor.                                                                             |

## init

Turns the camera on and initializes it in color sensor mode.

#### Syntax

{% tabs %}
{% tab title="JavaScript" %}

```javascript
brick.colorSensor("video1").init(true);
```

{% endtab %}

{% tab title="Python" %}

```
brick.colorSensor("video1").init(True);
```

{% endtab %}
{% endtabs %}

The boolean parameter defines whether to display the image from the camera:

* `true` — output,
* `false` — do not output

## read

Returns an array with the coordinates of the dominant color in the RGB color scale in the specified area of the frame.

The frame is divided into squares by a grid, by default 3 by 3, the dimensionality of the grid can be set in `model-config.xml` on the robot. Squares are indexed from 1. That is, (1, 1) is the upper-left edge of the frame, (2, 2) is its center.

The return value is an array of three elements from 0 to 255, indexed from 0. The zero element contains the intensity of red (0 - none at all, 255 - very much), the first - the intensity of green, the second - the intensity of blue. For example, (0, 0, 0) is black, (255, 255, 255) is white, (255, 0, 0) is red.

#### Syntax

{% tabs %}
{% tab title="JavaScript" %}

```javascript
brick.colorSensor("video1").read(x, y);
```

{% endtab %}

{% tab title="Python" %}

```
brick.colorSensor("video1").read(x, y);
```

{% endtab %}
{% endtabs %}

As a parameter, it is necessary to specify the indices of the square `x` and `y`.

## stop

Turns off the camera and stops the sensor.

#### Syntax

{% tabs %}
{% tab title="JavaScript" %}

```javascript
brick.colorSensor("video1").stop();
```

{% endtab %}

{% tab title="Python" %}

```
brick.colorSensor("video1").stop();
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.trikset.com/en/trik/programming-code/object-brick/class-colorsensor.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
