Light Sensor

group index

Overview

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.

Quick Start

  1. Add the following code to your application. This example initializes the Light Sensor and reads the relative brightness.

  2. Note: Define LIGHT_SENSOR_PIN as appropriate for your hardware

    #include "cyhal.h"
    #include "cybsp.h"
    #include "mtb_light_sensor.h"
    
    #define LIGHT_SENSOR_PIN (?) // Define me
    
    cyhal_adc_t adc;
    mtb_light_sensor_t sensor;
    
    int main(void)
    {
        cy_rslt_t result;
        result = cybsp_init();
        CY_ASSERT(result == CY_RSLT_SUCCESS);
    
        result = cyhal_adc_init(&adc, LIGHT_SENSOR_PIN, NULL);
        CY_ASSERT(result == CY_RSLT_SUCCESS);
    
        result = mtb_light_sensor_init(&light_sensor, &adc, LIGHT_SENSOR_PIN);
        CY_ASSERT(result == CY_RSLT_SUCCESS);
    
        uint8_t light = mtb_light_sensor_light_level(&light_sensor_obj));
    
        for(;;) { }
    }
    

More information