# ColorDistanceSensor

#### new ColorDistanceSensor()

Source:
  - devices/colordistancesensor.js, line 26

### Extends

- Device

### Members

#### (readonly) connected

##### Properties:

Name | Type | Description
--- | --- | ---
`connected` | boolean | Check if the device is still attached.

Inherited From:
  - Device#connected
Source:
  - devices/device.js, line 76

#### (readonly) hub

##### Properties:

Name | Type | Description
--- | --- | ---
`hub` | Hub | The Hub the device is attached to.

Inherited From:
  - Device#hub
Source:
  - devices/device.js, line 83

#### (readonly) isVirtualPort

##### Properties:

Name | Type | Description
--- | --- | ---
`isVirtualPort` | boolean | Is this device attached to a virtual port (ie. a combined device)

Inherited From:
  - Device#isVirtualPort
Source:
  - devices/device.js, line 120

#### (readonly) mode

##### Properties:

Name | Type | Description
--- | --- | ---
`mode` | number | The mode the device is currently in

Inherited From:
  - Device#mode
Source:
  - devices/device.js, line 110

#### (readonly) portName

##### Properties:

Name | Type | Description
--- | --- | ---
`portName` | string | The port the device is attached to.

Inherited From:
  - Device#portName
Source:
  - devices/device.js, line 93

#### (readonly) type

##### Properties:

Name | Type | Description
--- | --- | ---
`type` | number | The type of the device

Inherited From:
  - Device#type
Source:
  - devices/device.js, line 100

### Methods

#### sendPFIRMessage(message) → {Promise}

Send a raw Power Functions IR command

##### Parameters:

Name | Type | Description
--- | --- | ---
`message` | Buffer | 2 byte payload making up a Power Functions protocol command. NOTE: Only specify nibbles 1-3, nibble 4 should be zeroed.

Source:
  - devices/colordistancesensor.js, line 217

#### setColor(color) → {Promise}

Set the color of the LED on the sensor via a color value.

##### Parameters:

Name | Type | Description
--- | --- | ---
`color` | Color |

Source:
  - devices/colordistancesensor.js, line 235

#### setDistanceCount(distance) → {Promise}

Set the distance count value.

##### Parameters:

Name | Type | Description
--- | --- | ---
`distance` | count | count between 0 and 2^32

Source:
  - devices/colordistancesensor.js, line 256

#### setPFExtendedChannel(channel) → {Promise}

Switches the IR receiver into extended channel mode. After setting this, use channels 5-8 instead of 1-4 for this receiver.

NOTE: Calling this with channel 5-8 with switch off extended channel mode for this receiver.

##### Parameters:

Name | Type | Description
--- | --- | ---
`channel` | number | Channel number, between 1-8

Source:
  - devices/colordistancesensor.js, line 155

#### setPFPower(channel, output, power) → {Promise}

Set the power of a Power Functions motor via IR

##### Parameters:

Name | Type | Description
--- | --- | ---
`channel` | number | Channel number, between 1-4
`output` | string | Outport port, "RED" (A) or "BLUE" (B)
`power` | number | 7 (full reverse) to 7 (full forward). 0 is stop. 8 is brake.

Source:
  - devices/colordistancesensor.js, line 175

#### startPFMotors(channel, powerA, powerB) → {Promise}

Start Power Functions motors running via IR

NOTE: This command is designed for bang-bang style operation. To keep the motors running, the sensor needs to be within range of the IR receiver constantly.

##### Parameters:

Name | Type | Description
--- | --- | ---
`channel` | Buffer | Channel number, between 1-4
`powerA` | Buffer | 7 (full reverse) to 7 (full forward). 0 is stop. 8 is brake.
`powerB` | Buffer | 7 (full reverse) to 7 (full forward). 0 is stop. 8 is brake.

Source:
  - devices/colordistancesensor.js, line 195

### Events

#### ambient :object

Event measuring abient light change, emits when the sensor is activated.

##### Parameters:

Name | Type | Description
--- | --- | ---
`percentage` | number | from 0 to 100.

Source:
  - devices/colordistancesensor.js, line 102

#### color :object

Emits when a color sensor is activated.

##### Parameters:

Name | Type | Description
--- | --- | ---
`color` | Color |

Source:
  - devices/colordistancesensor.js, line 40

#### colorAndDistance :object

A combined color and distance event, emits when the sensor is activated.

##### Parameters:

Name | Type | Description
--- | --- | ---
`color` | Color |
`distance` | number | Distance, in millimeters.

Source:
  - devices/colordistancesensor.js, line 141

#### distance :object

Emits when a distance sensor is activated.

##### Parameters:

Name | Type | Description
--- | --- | ---
`distance` | number | Distance, in millimeters.

Source:
  - devices/colordistancesensor.js, line 58

#### distanceCount :object

Emits when distance is reduced to less than 10 centimeters.

##### Parameters:

Name | Type | Description
--- | --- | ---
`number` | number | of distance events.

Source:
  - devices/colordistancesensor.js, line 76

#### reflect :object

Event measuring reflection change, emits when the sensor is activated.

##### Parameters:

Name | Type | Description
--- | --- | ---
`percentage` | number | from 0 to 100.

Source:
  - devices/colordistancesensor.js, line 89

#### rgbIntensity :object

Emits when a color sensor is activated.

##### Parameters:

Name | Type | Description
--- | --- | ---
`red` | number |
`green` | number |
`blue` | number |

Source:
  - devices/colordistancesensor.js, line 121