task_light_sensor.c
/******************************************************************************
  * Returns the current ambient light value in lux
  ******************************************************************************/
Returns the current ambient light value in lux
Returns the current ambient light value in lux
uint32_t OPT3001_get_lux(void)
 {
        uint16_t exponent = 0;
        uint16_t fractional_result = 0;
        uint32_t result = 0;
        int16_t raw;
        raw = i2c_read_16(I2C_OPT3001_ADDRESS, I2C_OPT3001_RESULT_REG);
        result = raw&0x0FFF;
        exponent = (raw>>12)&0x000F;
        fractional_result = (raw&0x0FFF);
        result = 0.01*(2<<exponent)*fractional_result;
        return result;
 }
uint32_t OPT3001_get_lux ( void ) { uint16_t exponent = 0 ; uint16_t fractional_result = 0 ; uint32_t result = 0 ; int16_t raw ; raw = i2c_read_16 ( I2C_OPT3001_ADDRESS , I2C_OPT3001_RESULT_REG ) ; result = raw & 0x0FFF ; exponent = ( raw >> 12 ) & 0x000F ; fractional_result = ( raw & 0x0FFF ) ; result = 0.01 * ( 2 << exponent ) * fractional_result ; return result ; }
Returns the current ambient light value in lux
Returns the current ambient light value in lux
/*Convert to LUX*/ //extract result & exponent data from raw readings