Zigbee Module Examples

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hal_AMS_TCS3414_color_sensor.c File Reference

Interface driver to AMS/TAOS TCS3414 color sensor. More...

`#include "hal.h"`
`#include "hal_AMS_TCS3414_color_sensor.h"`
`#include "../Common/utilities.h"`
`#include <stdint.h>`
`#include <math.h>`

## Functions
uint8_t | readByte (uint8_t commandRegister)
void | writeByte (uint8_t commandRegister, uint8_t value)
uint16_t | readWord (uint8_t commandRegister, uint8_t readAddress)
void | colorSensorInit ()
uint16_t | convertRGBToCCT (uint16_t red, uint16_t green, uint16_t blue)
struct ColorReading | getColor (void)

## Detailed Description

Interface driver to AMS/TAOS TCS3414 color sensor.

# Usage

To use this driver in an application, include the following code:

        halInit();
        colorSensorInit();
        struct ColorReading color;
        color = getColor();
        printf("\r\nRED: %05u - BLUE: %05u - GREEN: %05u - CLEAR: %05u\r\n", color.red, color.blue, color.green, color.clear);

See also:
  http://www.ams.com/eng/Products/Light-Sensors/Color-Sensor/TCS3414

Rev:
  1528

Author:
  dsmith

Date:
  2012-08-30 15:58:08 -0700 (Thu, 30 Aug 2012)

# Support

Please refer to the wiki at www.anaren.com/air-wiki-zigbee for more information. Additional support is available via email at the following addresses:

- Questions on how to use the product: AIR@a.nosp@m.nare.nosp@m.n.com
- Feature requests, comments, and improvements: featu.nosp@m.rere.nosp@m.quest.nosp@m.s@te.nosp@m.slaco.nosp@m.ntro.nosp@m.ls.co.nosp@m.m
- Consulting engagements: sales.nosp@m.@tes.nosp@m.lacon.nosp@m.trol.nosp@m.s.com

# License

Copyright (c) 2012 Anaren Microwave. All rights reserved. This Software may only be used with an Anaren A2530E24AZ1, A2530E24CZ1, A2530R24AZ1, or A2530R24CZ1 module. Redistribution and use in source and binary forms, with or without modification, are subject to the Software License Agreement in the file "anaren_eula.txt"

YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL ANAREN MICROWAVE OR TESLA CONTROLS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSE INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.

## Function Documentation

void colorSensorInit | ( |  | ) |

    Configures the color sensor. Turns it on and configures the integration time. Also reads back the ID register.

Precondition:
  I2C interface on microcontroller was configured correctly

Note:
  Part maximum baud rate 400kHz for I2C.
  On powerup, the sensor is powered down and needs to be turned on before use.

uint16_t convertRGBToCCT | ( | uint16_t | red,
|  | uint16_t | green,
|  | uint16_t | blue
| ) |  |

Converts RGB values to Correlated Color Temperature (CCT). CCT is measured in Kelvin (K) and describes whether the ambient light is more warm (low CCT) or cool (high CCT). Typical CCT values are:

- Incandescent lamp: 3200K
- Cool White fluorescent lamp: 5000
- Overcast sky: 6500
  See also:
    http://en.wikipedia.org/wiki/Color_Temperature
    "Calculating Color Temperature and Illuminance using the TAOS TCS3414 Digital Color Sensor"
  Returns:
    color temperature in K

struct ColorReading getColor | ( | void |  | ) |
| read

    Read color values from the tcs3414 color sensor.

Returns:
  ColorReading structure containing values for Red, Green, Blue, and Clear sensor readings.

Precondition:
  I2C bus was configured properly and color sensor was initialized with colorSensorInit().

uint8_t readByte | ( | uint8_t | commandRegister | ) |

    Reads the 8-bit value of a single 8 bit register from the color sensor

Precondition:
  I2C bus was initialized with i2cInit(COLOR_SENSOR_I2C_ADDRESS)

Parameters:

  commandRegister | which register to write to

Returns:
  the value of the register

Note:
  could be implemented using i2cBlockRead too

uint16_t readWord | ( | uint8_t | commandRegister,
|  | uint8_t | readAddress
| ) |  |

    Reads the 16-bit value of a single 8 bit register from the color sensor

Precondition:
  I2C bus was initialized with i2cInit(COLOR_SENSOR_I2C_ADDRESS)

Parameters:

  commandRegister | which register to write to

Returns:
  the value of the register

void writeByte | ( | uint8_t | commandRegister,
|  | uint8_t | value
| ) |  |

    Writes the value of a single 8 bit register in the color sensor

Precondition:
  I2C bus was initialized with i2cInit(COLOR_SENSOR_I2C_ADDRESS)

Parameters:

  commandRegister | which register to write to
  value | the value to be written to the register