TCS3200 Arduino Library
Comprehensive Arduino library for TCS3200 Color Sensor.
Loading...
Searching...
No Matches
TCS3200 Class Reference

Class representing the TCS3200 color sensor. More...

#include <TCS3200.h>

Public Member Functions

 TCS3200 (uint8_t s0_pin, uint8_t s1_pin, uint8_t s2_pin, uint8_t s3_pin, uint8_t out_pin)
 Constructor for TCS3200 class.
 
void begin ()
 Initialize the TCS3200 sensor and configure pins.
 
uint8_t read_red ()
 Read the intensity of the red color channel.
 
uint8_t read_green ()
 Read the intensity of the green color channel.
 
uint8_t read_blue ()
 Read the intensity of the blue color channel.
 
uint8_t read_clear ()
 Read the intensity of the clear (ambient) color channel.
 
void calibrate ()
 Perform definition of the sensor as calibrated.
 
void calibrate_light ()
 Perform light calibration for white balancing.
 
void calibrate_dark ()
 Perform dark calibration for white balancing.
 
void integration_time (unsigned int time)
 Set the integration time for color sensing.
 
unsigned int integration_time ()
 Get the current integration time setting.
 
void frequency_scaling (int scaling)
 Set the frequency scaling for color sensing.
 
int frequency_scaling ()
 Get the current frequency scaling setting.
 
RGBColor read_rgb_color ()
 Read the RGB color values from the sensor.
 
RGBColor white_balance ()
 Get the current white balance RGB values.
 
void white_balance (RGBColor white_balance_rgb)
 Set the white balance RGB values.
 
HSVColor read_hsv ()
 Read the HSV color values from the sensor.
 
CMYKColor read_cmyk ()
 Read the CMYK color values from the sensor.
 
CIE1931Color read_cie1931 ()
 Read the CIE 1931 XYZ color values from the sensor.
 
float get_chroma ()
 Calculate the chroma of the current color readings.
 
uint8_t get_rgb_dominant_color ()
 Get the dominant RGB color channel.
 
void loop ()
 Continuously monitor color intensity values and trigger callbacks for interrupt conditions.
 
void upper_bound_interrupt (RGBColor threshold, void(*callback)())
 Enable an upper bound interrupt with a given threshold.
 
void lower_bound_interrupt (RGBColor threshold, void(*callback)())
 Enable a lower bound interrupt with a given threshold.
 
void clear_upper_bound_interrupt ()
 Clear the upper bound interrupt.
 
void clear_lower_bound_interrupt ()
 Clear the lower bound interrupt.
 
template<typename T >
nearest_color (T *color_labels, RGBColor *color_values, int size)
 Find the nearest color label based on the current sensor readings.
 

Detailed Description

Class representing the TCS3200 color sensor.

This class provides functions to interface with the TCS3200 color sensor, read color intensity values, perform calibration, white balancing, color space conversions, and nearest color detection. It also supports customization of integration time and frequency scaling.

Constructor & Destructor Documentation

◆ TCS3200()

TCS3200::TCS3200 ( uint8_t  s0_pin,
uint8_t  s1_pin,
uint8_t  s2_pin,
uint8_t  s3_pin,
uint8_t  out_pin 
)

Constructor for TCS3200 class.

Parameters
s0_pinArduino pin connected to S0 pin of the TCS3200.
s1_pinArduino pin connected to S1 pin of the TCS3200.
s2_pinArduino pin connected to S2 pin of the TCS3200.
s3_pinArduino pin connected to S3 pin of the TCS3200.
out_pinArduino pin connected to OUT pin of the TCS3200.

Member Function Documentation

◆ begin()

void TCS3200::begin ( )

Initialize the TCS3200 sensor and configure pins.

◆ calibrate()

void TCS3200::calibrate ( )

Perform definition of the sensor as calibrated.

This function defines the sensor as calibrated for the next reading to be more accurate. This function must be invoked after calling the functions calibrate_light() and calibrate_dark().

◆ calibrate_dark()

void TCS3200::calibrate_dark ( )

Perform dark calibration for white balancing.

This function reads color intensity values from the sensor under a dark surface and calculates the average values for each color channel. These values are used for white balancing future color readings.

◆ calibrate_light()

void TCS3200::calibrate_light ( )

Perform light calibration for white balancing.

This function reads color intensity values from the sensor under a well-lit white surface and calculates the average values for each color channel. These values are used for white balancing future color readings.

◆ clear_lower_bound_interrupt()

void TCS3200::clear_lower_bound_interrupt ( )

Clear the lower bound interrupt.

The previously registered callback function will no longer be executed when the condition is met.

◆ clear_upper_bound_interrupt()

void TCS3200::clear_upper_bound_interrupt ( )

Clear the upper bound interrupt.

The previously registered callback function will no longer be executed when the condition is met.

◆ frequency_scaling() [1/2]

int TCS3200::frequency_scaling ( )

Get the current frequency scaling setting.

Returns
Frequency scaling value.

◆ frequency_scaling() [2/2]

void TCS3200::frequency_scaling ( int  scaling)

Set the frequency scaling for color sensing.

Parameters
scalingFrequency scaling value.

◆ get_chroma()

float TCS3200::get_chroma ( )

Calculate the chroma of the current color readings.

Chroma represents the vividness or saturation of a color. It is calculated as the Euclidean distance of the color from the white point in the CIE 1931 XYZ color space.

\begin{equation} \text{Chroma} = \sqrt{(X - 0.95047)^2 + (Y - 1.0)^2 + (Z - 1.08883)^2} \end{equation}

Returns
Chroma value.

◆ get_rgb_dominant_color()

uint8_t TCS3200::get_rgb_dominant_color ( )

Get the dominant RGB color channel.

Returns
Dominant RGB color channel.

◆ integration_time() [1/2]

unsigned int TCS3200::integration_time ( )

Get the current integration time setting.

Returns
Integration time in microseconds.

◆ integration_time() [2/2]

void TCS3200::integration_time ( unsigned int  time)

Set the integration time for color sensing.

Parameters
timeIntegration time in microseconds.

◆ loop()

void TCS3200::loop ( )

Continuously monitor color intensity values and trigger callbacks for interrupt conditions.

This function should be called repeatedly in the main loop of your Arduino sketch to continuously monitor color intensity values from the sensor. If any interrupt conditions have been set using the upper_bound_interrupt() or lower_bound_interrupt() functions, the corresponding registered callback functions will be executed when the color intensity values meet the specified conditions.

For example, if an upper bound interrupt is set with a certain threshold color intensity, the callback function will be executed when the RGB color intensity values exceed the threshold. Similarly, if a lower bound interrupt is set, the callback function will be executed when the RGB color intensity values go below the threshold.

◆ lower_bound_interrupt()

void TCS3200::lower_bound_interrupt ( RGBColor  threshold,
void(*)()  callback 
)

Enable a lower bound interrupt with a given threshold.

When the color intensity values go below the threshold, the registered callback function will be executed.

Parameters
thresholdRGBColor threshold for the lower bound interrupt.
callbackFunction pointer to the callback function.

◆ nearest_color()

template<typename T >
T TCS3200::nearest_color ( T *  color_labels,
RGBColor color_values,
int  size 
)
inline

Find the nearest color label based on the current sensor readings.

Template Parameters
TType of the color label (e.g., String, char[]).
Parameters
color_labelsArray of color labels.
color_valuesArray of corresponding RGBColor values.
sizeSize of the arrays.
Returns
Nearest color label of type T.

◆ read_blue()

uint8_t TCS3200::read_blue ( )

Read the intensity of the blue color channel.

Returns
Blue color intensity (0-255).

◆ read_cie1931()

CIE1931Color TCS3200::read_cie1931 ( )

Read the CIE 1931 XYZ color values from the sensor.

Returns
CIE1931Color representing the current color readings in the CIE 1931 XYZ color space.

◆ read_clear()

uint8_t TCS3200::read_clear ( )

Read the intensity of the clear (ambient) color channel.

Returns
Clear color intensity (0-255).

◆ read_cmyk()

CMYKColor TCS3200::read_cmyk ( )

Read the CMYK color values from the sensor.

Returns
CMYKColor representing the current color readings in the CMYK color space.

◆ read_green()

uint8_t TCS3200::read_green ( )

Read the intensity of the green color channel.

Returns
Green color intensity (0-255).

◆ read_hsv()

HSVColor TCS3200::read_hsv ( )

Read the HSV color values from the sensor.

Returns
HSVColor representing the current color readings in the HSV color space.

◆ read_red()

uint8_t TCS3200::read_red ( )

Read the intensity of the red color channel.

Returns
Red color intensity (0-255).

◆ read_rgb_color()

RGBColor TCS3200::read_rgb_color ( )

Read the RGB color values from the sensor.

Returns
RGBColor representing the current color readings.

◆ upper_bound_interrupt()

void TCS3200::upper_bound_interrupt ( RGBColor  threshold,
void(*)()  callback 
)

Enable an upper bound interrupt with a given threshold.

When the color intensity values exceed the threshold, the registered callback function will be executed.

Parameters
thresholdRGBColor threshold for the upper bound interrupt.
callbackFunction pointer to the callback function.

◆ white_balance() [1/2]

RGBColor TCS3200::white_balance ( )

Get the current white balance RGB values.

Returns
RGBColor representing white balance values.

◆ white_balance() [2/2]

void TCS3200::white_balance ( RGBColor  white_balance_rgb)

Set the white balance RGB values.

Parameters
white_balance_rgbRGBColor representing white balance values.

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