Main Content

readColor

Reads clear light and RGB components through APDS9960 sensor

Description

[colorData,timestamp] = readColor(apds9960obj) returns the RGB component values of the sensed light along with the timestamp. The object function normalizes the RGB values using the clear light intensity value. The Timestamp argument is optional.

[colorData,timestamp] = readColor(apds9960obj, colorMode) returns the RGB component values of the sensed light along with the timestamp depending on the ColorMode argument. The Timestamp argument is optional. The RGB values are normalised using the clear light intensity value

Examples

Read Color from Sensor

Create an Arduino object.

arduinoobj = arduino('COM4', 'Nano33BLE', 'Libraries', 'APDS9960');

Create the sensor object for the sensor.

apds9960obj = apds9960(arduinoobj)

Read color data from sensor by setting the ColorMode property to normalized.

Note

Sensor readings after 200 ms are accurate while using the readColor function.

The function returns the color data as a three-element vector of the RGB components.

[colorData, timestamp] = readColor(apds9960obj, 'normalized')
colorData = 1×3
    0.6000    0.4000    0.4000
timestamp = datetime
   17-Jun-2021 13:25:27

Read color data from sensor by setting the ColorMode property to raw.

The first member of the vector of the output is the clear light intensity and the subsequent members are the R, G, and B component values.

[colorData, timestamp] = readColor(apds9960obj, 'raw')
colorData = 1×4 uint16 row vector
   5   2   2   2
timestamp = datetime
   17-Jun-2021 13:25:28

Input Arguments

collapse all

APDS9960 sensor connection, specified as a apds9960 sensor object.

When you set the colorMode to normalized, the object function normalizes the RGB values using the clear light intensity value.

Data Types: Char | String

Output Arguments

collapse all

The color data read, varies depending on the value of the colorMode property with 0 representing complete darkness.

Color ModeOutput SizeOutput
'normalized'1 by 3 vector with datatype doubleThe output vector contains the R, G, B component values
'raw'1 by 4 vector with datatype uint16The output vector contains the clear light value and R, G, B component values

Data Types: Vector

The time at which MATLAB® receives the color data from the sensor, specified as a datetime.

Introduced in R2021b