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.
#define S0_PIN 15
#define S1_PIN 2
#define S2_PIN 0
#define S3_PIN 4
#define OUT_PIN 16
TCS3200 tcs3200(S0_PIN, S1_PIN, S2_PIN, S3_PIN, OUT_PIN);
String color_indices[] = {"Red", "Green", "Blue"};
{255, 0, 0},
{0, 255, 0},
{0, 0, 255},
};
void setup() {
tcs3200.begin();
Serial.begin(115200);
Serial.println("TCS3200 Full Example");
Serial.println("-----------------------------------");
Serial.println("Calibrating...");
Serial.println("Please face the sensor to white surface.");
delay(1000);
tcs3200.calibrate_light();
Serial.println("Please face the sensor to dark surface.");
delay(1000);
tcs3200.calibrate_dark();
Serial.println("Done calibrating!");
tcs3200.calibrate();
delay(1000);
}
void loop() {
tcs3200.loop();
Serial.println("-----------------------------------");
RGBColor rgb_color = tcs3200.read_rgb_color();
Serial.println(
"Red: " + String(rgb_color.
red) +
", Green: " + String(rgb_color.
green) +
", Blue: " + String(rgb_color.
blue));
Serial.println(
"Cyan: " + String(cmyk_color.
cyan) +
", Magenta: " + String(cmyk_color.
magenta) +
", Yellow: " + String(cmyk_color.
yellow) +
", Black: " + String(cmyk_color.
black));
Serial.println(
"Hue: " + String(hsv.
hue) +
", Value: " + String(hsv.
value));
Serial.println(
"X: " + String(cie1931.
x) +
", Y: " + String(cie1931.
y) +
", Z: " + String(cie1931.
z));
Serial.println("Chroma: " + String(tcs3200.get_chroma()));
Serial.println("Dominant color: " +
color_indices[tcs3200.get_rgb_dominant_color()]);
Serial.println("Nearest color: " +
tcs3200.nearest_color<String>(
color_indices,
color_values,
sizeof(color_indices) / sizeof(color_indices[0])
)
);
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