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. TheTimestampargument is optional.

[colorData,timestamp] = readColor(apds9960obj,colorMode)returns the RGB component values of the sensed light along with the timestamp depending on theColorMode论点。的Timestampargument 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 theColorModeproperty tonormalized.

Note

Sensor readings after 200 ms are accurate while using thereadColorfunction.

的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 theColorModeproperty toraw.

的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 aapds9960sensor object.

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

Data Types:Char|String

Output Arguments

collapse all

的color data read, varies depending on the value of thecolorModeproperty with0representing complete darkness.

Color Mode Output Size Output
'normalized' 1 by 3 vector with datatypedouble 的output vector contains the R, G, B component values
'raw' 1 by 4 vector with datatypeuint16 的output vector contains the clear light value and R, G, B component values

Data Types:Vector

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

Version History

Introduced in R2021b