API Reference

group group_board_libs

Basic set of APIs for interacting with the light sensor.


cy_rslt_t mtb_light_sensor_init(mtb_light_sensor_t *light_sensor, cyhal_adc_t *adc_obj, cyhal_gpio_t pin)

Initialize the ADC communication with the light sensor.


The ADC initialization function, cyhal_adc_init(), must be called before this function is called.

  • light_sensor[out] Pointer to a Light Sensor object. The caller must allocate the memory for this object but the init function will initialize its contents.

  • adc_obj[in] ADC instance to use for communicating with the light sensor.

  • pin[in] The pin connected to the light sensor.


CY_RSLT_SUCCESS if properly initialized, else an error indicating what went wrong.

uint8_t mtb_light_sensor_light_level(mtb_light_sensor_t *light_sensor)

Returns the current light level.


light_sensor[in] Light sensor instance.


A percentage - a value between 0 (no light) and 100 (maximum measurable light).

void mtb_light_sensor_free(mtb_light_sensor_t *light_sensor)

Frees up any resources allocated by the light sensor as part of mtb_light_sensor_init().


light_sensor[in] Light sensor instance.

struct mtb_light_sensor_t
#include <>

Structure defining the pin and ADC channel used to interact with the light sensor.