| MD_TCS230 Color Sensor Arduino Library 1.2 Library to control TCS230 Color Sensor

Public Member Functions | List of all members
MD_TCS230 Class Reference

`#include <MD_TCS230.h>`

## Public Member Functions
| MD_TCS230 (uint8_t s2, uint8_t s3)
| MD_TCS230 (uint8_t s2, uint8_t s3, uint8_t oe)
| MD_TCS230 (uint8_t s2, uint8_t s3, uint8_t s0, uint8_t s1)
| MD_TCS230 (uint8_t s2, uint8_t s3, uint8_t s0, uint8_t s1, uint8_t oe)
void | begin (void)
| ~MD_TCS230 (void)
Methods for hardware and object control.
void | setFilter (uint8_t f)
void | setFrequency (uint8_t f)
void | setEnable (bool t)
void | setSampling (uint8_t t)
void | setDarkCal (sensorData *d)
void | setWhiteCal (sensorData *d)
Methods for reading sensor data.
void | read (void)
bool | available (void)
void | getRGB (colorData *rgb)
void | getRaw (sensorData *d)
uint32_t | readSingle (void)

## Detailed Description

Core object for the MD_MAX72XX library This is the only class implemented to abstract and manage the sensor.

## Constructor & Destructor Documentation

## ◆ MD_TCS230() [1/4]

MD_TCS230::MD_TCS230 | ( | uint8_t | s2,
|  | uint8_t | s3
| ) |  |

Class Constructor - minimal interface.

Instantiate a new instance of the class. The parameters passed are used to connect the software to the hardware.

The minimum required to manage the sensor are the s1 and s2 pins for color filter selection.

Parameters

  s2 | Arduino output pin connected to sensor s2 input.
  s3 | Arduino output pin connected to sensor s3 input.

## ◆ MD_TCS230() [2/4]

MD_TCS230::MD_TCS230 | ( | uint8_t | s2,
|  | uint8_t | s3,
|  | uint8_t | oe
| ) |  |

Class Constructor - minimal with multiple sensors.

Instantiate a new instance of the class. The parameters passed are used to connect the software to the hardware.

The minimum required to manage the sensor are the s2 and s3 pins for color filter selection. Optionally, the oe pin can be specified if multiple sensors are to be connected, however read the separate documentation on the hardware supported to ensure that the sensor module is suitably modified if control using oe is required.

Parameters

  s2 | Arduino output pin connected to sensor s2 input.
  s3 | Arduino output pin connected to sensor s3 input.
  oe | Arduino output pin connected to sensor oe input.

## ◆ MD_TCS230() [3/4]

MD_TCS230::MD_TCS230 | ( | uint8_t | s2,
|  | uint8_t | s3,
|  | uint8_t | s0,
|  | uint8_t | s1
| ) |  |

Class Constructor - prescaler control interface.

Instantiate a new instance of the class. The parameters passed are used to connect the software to the hardware.

The minimum required to manage the sensor are the s1 and s2 pins for color filter selection. Optionally, s0 and s1 can be specified to allow changes to the prescaler.

Parameters

  s2 | Arduino output pin connected to sensor s2 input.
  s3 | Arduino output pin connected to sensor s3 input.
  s0 | Arduino output pin connected to sensor s0 input.
  s1 | Arduino output pin connected to sensor s1 input.

## ◆ MD_TCS230() [4/4]

MD_TCS230::MD_TCS230 | ( | uint8_t | s2,
|  | uint8_t | s3,
|  | uint8_t | s0,
|  | uint8_t | s1,
|  | uint8_t | oe
| ) |  |

Class Constructor - prescaler and multiple sensors interface.

Instantiate a new instance of the class. The parameters passed are used to connect the software to the hardware.

The minimum required to manage the sensor are the s1 and s2 pins for color filter selection. Optionally, s0 and s1 can be specified to allow changes to the prescaler. Additionally, the oe pin can be specified if multiple sensors are to be connected, however read the separate documentation on the hardware supported to ensure that the sensor module is suitably modified if control using oe is required.

Parameters

  s2 | Arduino output pin connected to sensor s2 input.
  s3 | Arduino output pin connected to sensor s3 input.
  s0 | Arduino output pin connected to sensor s0 input.
  s1 | Arduino output pin connected to sensor s1 input.
  oe | Arduino output pin connected to sensor oe input.

## ◆ ~MD_TCS230()

MD_TCS230::~MD_TCS230 | ( | void |  | ) |

Class Destructor.

Released allocated memory and does the necessary to clean up once the object is no longer required.

## Member Function Documentation

## ◆ available()

bool MD_TCS230::available | ( | void |  | ) |

Determine when a sensor read has completed.

The method will return true when a value is ready for processing, at which time a call to getRGB() or getRaw() will retrieve the data for the calling program.

Returns
  true if data is available, false otherwise.

## ◆ begin()

void MD_TCS230::begin | ( | void |  | ) |

Initialize the object.

Initialize the object data. The object needs to initialize itself during using Arduino libraries and so cannot be completely initialized in the constructor. Should be called once during setup() for every object instance.

## ◆ getRaw()

void MD_TCS230::getRaw | ( | sensorData * | d | ) |

Get raw data from the last sensor reading.

Get the last read sensor data as raw counts into the structure d. The raw counts may be retrieved using value[TCS230_RGB_] for the Red, Green and Blue elements, respectively.

Parameters

  d | Pointer to a sensorData structure to receive the RGB data.

## ◆ getRGB()

void MD_TCS230::getRGB | ( | colorData * | rgb | ) |

Get RGB color data for the last sensor reading.

Get the last read sensor data in RGB format into the structure rgb. The elements of RGB are retrieved using value[TCS230_RGB_] for the Red, Green and Blue elements, respectively.

Parameters

  rgb | Pointer to a colorData structure to receive the RGB data.

## ◆ read()

void MD_TCS230::read | ( | void |  | ) |

Start an asynchronous read cycle.

The function will coordinate enabling the sensor, selecting the right filters in sequence and calling the FreqCount library to obtain a full color reading (all of R, G,and B).

## ◆ readSingle()

uint32_t MD_TCS230::readSingle | ( | void |  | ) |

Synchronously read a value (blocking read)

Initiate a blocking read of the sensor. The method returns the raw data read from the sensor as a uint32_t, normalized to a value in Hz, once the read cycle is completed. How long this takes is determined by the sampling period set using setSampling(). The calling program is responsible for enabling the device using setEnable() and setting the appropriate color filter using setFilter().

Returns
  raw data read from the sensor in Hz.

## ◆ setDarkCal()

void MD_TCS230::setDarkCal | ( | sensorData * | d | ) |

Set the dark calibration data.

Sets the values to be used as the dark calibration data. These numbers can be obtained from getRaw() during the calibration process.

Parameters

  d | Pointer to a sensorData structure containing the calibration data.

## ◆ setEnable()

void MD_TCS230::setEnable | ( | bool | t | ) |

Enable or disable sensor output (using OE or frequency).

Enable (true) or disable (false) sensor output by (in order of preference):

1 If the OE pin is defined, setting the OE pin to the appropriate HIGH/LOW conditions. This is preferred mode as the high impedance mode can be used for OUT signal isolation.

2 If the SO and S1 pins are defined, setting the output frequency to the value set by the setFrequency() method or to TCS230_FREQ_OFF.

3 No action is taken if none of OE, S0 and S1 is defined.

Parameters

  t | True to enable the device, false to disable.

## ◆ setFilter()

void MD_TCS230::setFilter | ( | uint8_t | f | ) |

Set the photodiode filter.

Set the outputs s0, s1 to match the specified photodiode filter. This is one of the defined values TCS230_RGB_*.

The read() method will automatically invoke all the filters in turn.

Parameters

  f | The required filter, one of TCS230_RGB_*.

## ◆ setFrequency()

void MD_TCS230::setFrequency | ( | uint8_t | f | ) |

Set the frequency prescaler.

Set the outputs s2, s3 to match the specified frequency prescaler. This is one of the defined values TCS230_FREQ_*.

Default library value is 100% prescaler (TCS23_FREQ_HI).

This method will only work if the prescaler pins s2, s3 are specified in the constructor and is ignored otherwise.

Parameters

  f | The required filter, one of TCS230_RGB_*.

## ◆ setSampling()

void MD_TCS230::setSampling | ( | uint8_t | t | ) |

Set the sampling period divisor.

The library is set for a maximum of 1000ms for a sample (divisor = 1). Higher divisors create shorter sample times (eg, 5 = 200ms, 10 = 100ms, 100 = 10ms). Shorter samples are less accurate and only recommended when the range of colors to be detected are highly separated on the RGB color chart. The ‘right’ value for the divisor is dependent on the application.

The default value is 10 (100ms sample).

Parameters

  t | Cycle time divisor.

## ◆ setWhiteCal()

void MD_TCS230::setWhiteCal | ( | sensorData * | d | ) |

Set the white balance calibration data.

Sets the values to be used as the white balance calibration data. These numbers can be obtained from getRaw() during the calibration process.

Parameters

  d | Pointer to a sensorData structure containing the calibration data.

The documentation for this class was generated from the following files:

- src/MD_TCS230.h
- src/MD_TCS230.cpp