TCS3200 Arduino Library
Comprehensive Arduino library for TCS3200 Color Sensor.
|
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 > | |
T | nearest_color (T *color_labels, RGBColor *color_values, int size) |
Find the nearest color label based on the current sensor readings. | |
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.
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.
s0_pin | Arduino pin connected to S0 pin of the TCS3200. |
s1_pin | Arduino pin connected to S1 pin of the TCS3200. |
s2_pin | Arduino pin connected to S2 pin of the TCS3200. |
s3_pin | Arduino pin connected to S3 pin of the TCS3200. |
out_pin | Arduino pin connected to OUT pin of the TCS3200. |
void TCS3200::begin | ( | ) |
Initialize the TCS3200 sensor and configure pins.
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()
.
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.
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.
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.
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.
int TCS3200::frequency_scaling | ( | ) |
Get the current frequency scaling setting.
void TCS3200::frequency_scaling | ( | int | scaling | ) |
Set the frequency scaling for color sensing.
scaling | Frequency scaling value. |
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}
uint8_t TCS3200::get_rgb_dominant_color | ( | ) |
Get the dominant RGB color channel.
unsigned int TCS3200::integration_time | ( | ) |
Get the current integration time setting.
void TCS3200::integration_time | ( | unsigned int | time | ) |
Set the integration time for color sensing.
time | Integration time in microseconds. |
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.
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.
threshold | RGBColor threshold for the lower bound interrupt. |
callback | Function pointer to the callback function. |
|
inline |
Find the nearest color label based on the current sensor readings.
T | Type of the color label (e.g., String, char[]). |
color_labels | Array of color labels. |
color_values | Array of corresponding RGBColor values. |
size | Size of the arrays. |
uint8_t TCS3200::read_blue | ( | ) |
Read the intensity of the blue color channel.
CIE1931Color TCS3200::read_cie1931 | ( | ) |
Read the CIE 1931 XYZ color values from the sensor.
uint8_t TCS3200::read_clear | ( | ) |
Read the intensity of the clear (ambient) color channel.
CMYKColor TCS3200::read_cmyk | ( | ) |
Read the CMYK color values from the sensor.
uint8_t TCS3200::read_green | ( | ) |
Read the intensity of the green color channel.
HSVColor TCS3200::read_hsv | ( | ) |
Read the HSV color values from the sensor.
uint8_t TCS3200::read_red | ( | ) |
Read the intensity of the red color channel.
RGBColor TCS3200::read_rgb_color | ( | ) |
Read the RGB color values from the sensor.
RGBColor
representing the current color readings. 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.
threshold | RGBColor threshold for the upper bound interrupt. |
callback | Function pointer to the callback function. |
RGBColor TCS3200::white_balance | ( | ) |
Get the current white balance RGB values.
RGBColor
representing white balance values. void TCS3200::white_balance | ( | RGBColor | white_balance_rgb | ) |
Set the white balance RGB values.
white_balance_rgb | RGBColor representing white balance values. |