This library provides functions to support use of a phototransistor ambient light sensor such as the TEMT6000 as used on the CY8CKIT-028-TFT shield. It uses an ADC to read the relative light level which is returned a a percentage of maximum brightness (0-100).
This library is generic and can be used with any ADC based light sensor.
- Create an empty application
- Add this library to the application
- Add the following code to your application. This example initializes the Light Sensor and reads the relative brightness.
\note This example is targeted for Arduino-based boards. Define LIGHT_SENSOR_PIN as appropriate for your hardware.
#include "cyhal.h"
#include "cybsp.h"
#include "mtb_light_sensor.h"
#define LIGHT_SENSOR_PIN (CYBSP_A0)
cyhal_adc_t adc;
mtb_light_sensor_t light_sensor;
int main(void)
{
cy_rslt_t rslt;
rslt = cybsp_init();
CY_ASSERT(rslt == CY_RSLT_SUCCESS);
rslt = cyhal_adc_init(&adc, LIGHT_SENSOR_PIN, NULL);
CY_ASSERT(rslt == CY_RSLT_SUCCESS);
rslt = mtb_light_sensor_init(&light_sensor, &adc, LIGHT_SENSOR_PIN);
CY_ASSERT(rslt == CY_RSLT_SUCCESS);
uint8_t light = mtb_light_sensor_light_level(&light_sensor);
for(;;) { }
}
- API Reference Guide
- Cypress Semiconductor, an Infineon Technologies Company
- Infineon GitHub
- ModusToolbox™
- PSoC™ 6 Code Examples using ModusToolbox™ IDE
- ModusToolbox™ Software
- PSoC™ 6 Resources - KBA223067
© Cypress Semiconductor Corporation (an Infineon company) or an affiliate of Cypress Semiconductor Corporation, 2019-2021.