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

TCS3200 Color Sensor Arduino Library More...

#include <Arduino.h>

Go to the source code of this file.

Classes

struct  _RGBColor
 Structure to represent RGB color values. More...
 
struct  _HSVColor
 Structure to represent HSV color values. More...
 
struct  _CMYKColor
 Structure to represent CMYK color values. More...
 
struct  _CIE1931
 Structure to represent CIE 1931 XYZ color values. More...
 
class  TCS3200
 Class representing the TCS3200 color sensor. More...
 

Macros

#define TCS3200_COLOR_RED   0x00
 Red color channel for filtering.
 
#define TCS3200_COLOR_GREEN   0x01
 Green color channel for filtering.
 
#define TCS3200_COLOR_BLUE   0x02
 Blue color channel for filtering.
 
#define TCS3200_COLOR_CLEAR   0x03
 Clear color channel for filtering.
 
#define TCS3200_PWR_DOWN   0x00
 Power down mode.
 
#define TCS3200_OFREQ_2P   0x01
 2% frequency scaling
 
#define TCS3200_OFREQ_20P   0x02
 20% frequency scaling
 
#define TCS3200_OFREQ_100P   0x03
 100% frequency scaling
 

Typedefs

typedef struct _RGBColor RGBColor
 Structure to represent RGB color values.
 
typedef struct _HSVColor HSVColor
 Structure to represent HSV color values.
 
typedef struct _CMYKColor CMYKColor
 Structure to represent CMYK color values.
 
typedef struct _CIE1931 CIE1931Color
 Structure to represent CIE 1931 XYZ color values.
 

Detailed Description

TCS3200 Color Sensor Arduino Library

Author
Nathanne Isip

This library provides a comprehensive set of functions to interface with the TCS3200 color sensor. It enables users to read color intensity values from the sensor, perform calibration, white balancing, color space conversions, and nearest color detection. The library supports customization of integration time and frequency scaling to optimize color sensing for specific applications.

Example usage:

// TCS3200 Library Full Example
// By: Nathanne Isip
// 31 July 2023
#include <tcs3200.h>
// Define pin connections
#define S0_PIN 15
#define S1_PIN 2
#define S2_PIN 0
#define S3_PIN 4
#define OUT_PIN 16
// Create an instance of the TCS3200 class
TCS3200 tcs3200(S0_PIN, S1_PIN, S2_PIN, S3_PIN, OUT_PIN);
// Define color labels for identification
String color_indices[] = {"Red", "Green", "Blue"};
// Define RGB color values corresponding to the color labels
RGBColor color_values[] = {
{255, 0, 0}, // Red
{0, 255, 0}, // Green
{0, 0, 255}, // Blue
};
void setup() {
// Initialize the TCS3200 sensor and set frequency scaling to 20%
tcs3200.begin();
tcs3200.frequency_scaling(TCS3200_OFREQ_20P);
// Initialize Serial communication for output
Serial.begin(115200);
Serial.println("TCS3200 Full Example");
Serial.println("-----------------------------------");
// Calibrate the sensor for accurate color readings
Serial.println("Calibrating...");
// Calibrate the sensor for light surface (white calibration)
Serial.println("Please face the sensor to white surface.");
delay(1000);
tcs3200.calibrate_light();
// Calibrate the sensor for dark surface (black calibration)
Serial.println("Please face the sensor to dark surface.");
delay(1000);
tcs3200.calibrate_dark();
// Complete calibration and enable calibrated readings
Serial.println("Done calibrating!");
tcs3200.calibrate();
// Add a delay to allow time for the serial output to be read
delay(1000);
}
void loop() {
// Allow the TCS3200 sensor to check for interrupt conditions (if set)
tcs3200.loop();
Serial.println("-----------------------------------");
// Read and display RGB color values
RGBColor rgb_color = tcs3200.read_rgb_color();
Serial.println("Red: " + String(rgb_color.red) +
", Green: " + String(rgb_color.green) +
", Blue: " + String(rgb_color.blue));
// Read and display CMYK color values
CMYKColor cmyk_color = tcs3200.read_cmyk();
Serial.println("Cyan: " + String(cmyk_color.cyan) +
", Magenta: " + String(cmyk_color.magenta) +
", Yellow: " + String(cmyk_color.yellow) +
", Black: " + String(cmyk_color.black));
// Read and display HSV (Hue, Saturation, Value) color values
HSVColor hsv = tcs3200.read_hsv();
Serial.println("Hue: " + String(hsv.hue) +
", Saturation: " + String(hsv.saturation) +
", Value: " + String(hsv.value));
// Read and display CIE 1931 color values
CIE1931Color cie1931 = tcs3200.read_cie1931();
Serial.println("X: " + String(cie1931.x) +
", Y: " + String(cie1931.y) +
", Z: " + String(cie1931.z));
// Calculate and display the Chroma value
Serial.println("Chroma: " + String(tcs3200.get_chroma()));
// Determine the dominant color from RGB values and display the result
Serial.println("Dominant color: " +
color_indices[tcs3200.get_rgb_dominant_color()]);
// Find and display the nearest color label to the current RGB values
Serial.println("Nearest color: " +
tcs3200.nearest_color<String>(
color_indices,
color_values,
sizeof(color_indices) / sizeof(color_indices[0])
)
);
// Add a delay before repeating the loop
delay(3000);
}
TCS3200 Color Sensor Arduino Library
#define TCS3200_OFREQ_20P
20% frequency scaling
Definition TCS3200.h:159
Class representing the TCS3200 color sensor.
Definition TCS3200.h:219
Structure to represent CIE 1931 XYZ color values.
Definition TCS3200.h:201
float y
Y value.
Definition TCS3200.h:203
float x
X value.
Definition TCS3200.h:202
float z
Z value.
Definition TCS3200.h:204
Structure to represent CMYK color values.
Definition TCS3200.h:189
float black
Black (Key) color intensity (0-1)
Definition TCS3200.h:193
float yellow
Yellow color intensity (0-1)
Definition TCS3200.h:192
float cyan
Cyan color intensity (0-1)
Definition TCS3200.h:190
float magenta
Magenta color intensity (0-1)
Definition TCS3200.h:191
Structure to represent HSV color values.
Definition TCS3200.h:178
float hue
Hue value in degrees (0-360)
Definition TCS3200.h:179
float value
Value (brightness) value (0-1)
Definition TCS3200.h:181
float saturation
Saturation value (0-1)
Definition TCS3200.h:180
Structure to represent RGB color values.
Definition TCS3200.h:167
uint8_t red
Red color intensity (0-255)
Definition TCS3200.h:168
uint8_t blue
Blue color intensity (0-255)
Definition TCS3200.h:170
uint8_t green
Green color intensity (0-255)
Definition TCS3200.h:169

Typedef Documentation

◆ CIE1931Color

typedef struct _CIE1931 CIE1931Color

Structure to represent CIE 1931 XYZ color values.

◆ CMYKColor

typedef struct _CMYKColor CMYKColor

Structure to represent CMYK color values.

◆ HSVColor

typedef struct _HSVColor HSVColor

Structure to represent HSV color values.

◆ RGBColor

typedef struct _RGBColor RGBColor

Structure to represent RGB color values.