SPIKE-RT C API Reference [English]
An RTOS-based software platform for LEGO® Education SPIKE™.
Data Structures | Typedefs | Functions
Color Sensor

APIs for color sensors. More...

Data Structures

struct  pup_color_rgb_t
 Returns the raw RGB values measured by the color sensor. More...
 

Typedefs

typedef pbio_color_hsv_t pup_color_hsv_t
 Get the color of surface or an extra source by a color sensor. More...
 

Functions

pup_device_tpup_color_sensor_get_device (pbio_port_id_t port)
 Get the PUP device pointer of the color sensor specified with the port ID. More...
 
pup_color_rgb_t pup_color_sensor_rgb (pup_device_t *pdev)
 
pup_color_hsv_t pup_color_sensor_color (pup_device_t *pdev, bool surface)
 
pup_color_hsv_t pup_color_sensor_hsv (pup_device_t *pdev, bool surface)
 Get the color of surface or an extra source by a color sensor. More...
 
int32_t pup_color_sensor_reflection (pup_device_t *pdev)
 Get the percentage of how much a surface reflects the light emmited by the sensor. More...
 
int32_t pup_color_sensor_ambient (pup_device_t *pdev)
 Get the ambient light intensity. More...
 
pbio_error_t pup_color_sensor_light_set (pup_device_t *pdev, int32_t bv1, int32_t bv2, int32_t bv3)
 Set the three light brightneses of the color sensor. More...
 
pbio_error_t pup_color_sensor_light_on (pup_device_t *pdev)
 Set the three light brightneses of the color sensor. More...
 
pbio_error_t pup_color_sensor_light_off (pup_device_t *pdev)
 Set the three light brightneses of the color sensor. More...
 
pup_color_hsv_tpup_color_sensor_detectable_colors (int32_t size, pup_color_hsv_t *colors)
 Configure colors which color sensor should detect. More...
 

Detailed Description

APIs for color sensors.

Typedef Documentation

◆ pup_color_hsv_t

typedef pbio_color_hsv_t pup_color_hsv_t

Get the color of surface or an extra source by a color sensor.

By default, it detects red, yellow, green, blue, white, none. You can choose color detected by pup_detectale_colors()

Parameters
pdevPUP device pointer to be inquired.
trueScan from a surface.
falseScan from a external light sources.
Returns
Color in hsv style.

Function Documentation

◆ pup_color_sensor_ambient()

int32_t pup_color_sensor_ambient ( pup_device_t pdev)

Get the ambient light intensity.

Parameters
pdevPUP device pointer to be inquired.
Returns
Ambient light intensity in percentage style.

◆ pup_color_sensor_detectable_colors()

pup_color_hsv_t * pup_color_sensor_detectable_colors ( int32_t  size,
pup_color_hsv_t colors 
)

Configure colors which color sensor should detect.

Parameters
sizeSize of the colors array.
colorsArray of colors.
Return values
errError number.

◆ pup_color_sensor_get_device()

pup_device_t * pup_color_sensor_get_device ( pbio_port_id_t  port)

Get the PUP device pointer of the color sensor specified with the port ID.

If it fails, it outputs an error log and returns NULL.

Parameters
portPUP port ID to be inquired.
Returns
pdev PUP device pointer.

◆ pup_color_sensor_hsv()

pup_color_hsv_t pup_color_sensor_hsv ( pup_device_t pdev,
bool  surface 
)

Get the color of surface or an extra source by a color sensor.

Unlike pup_color_sensor_color(), it gives the hsv detected directly, instead of rounding it to the nearest detectable colors.

Parameters
pdevPUP device pointer to be inquired.
trueScan from a surface.
falseScan from a external light sources.
Returns
Color in hsv style.

◆ pup_color_sensor_light_off()

pbio_error_t pup_color_sensor_light_off ( pup_device_t pdev)

Set the three light brightneses of the color sensor.

Same as pup_color_sensor_light_set(pdev, 0, 0, 0)

Parameters
pdevPUP device pointer.
Return values
errError number.

◆ pup_color_sensor_light_on()

pbio_error_t pup_color_sensor_light_on ( pup_device_t pdev)

Set the three light brightneses of the color sensor.

Same as pup_color_sensor_light_set(pdev, 100, 100, 100)

Parameters
pdevPUP device pointer.
Return values
errError number.

◆ pup_color_sensor_light_set()

pbio_error_t pup_color_sensor_light_set ( pup_device_t pdev,
int32_t  bv1,
int32_t  bv2,
int32_t  bv3 
)

Set the three light brightneses of the color sensor.

Parameters
pdevPUP device pointer.
bv1Brightness.
Return values
errError number.

◆ pup_color_sensor_reflection()

int32_t pup_color_sensor_reflection ( pup_device_t pdev)

Get the percentage of how much a surface reflects the light emmited by the sensor.

Parameters
pdevPUP device pointer to be inquired.
Returns
Mesured reflection in percentage style.