TCS34725
The TCS34725 is a color light-to-digital converter that provides digital readings for red, green, blue (RGB), and clear light sensing values. In a specific application, it was utilized to detect black and blue tiles. The sensor was strategically positioned at the bottom front of the robot, allowing it to have a time buffer for timely responses.
The main methods used were:
Processing RGB input
he idea behind our implementation to relate a RGB output with a color was very simple:
- For each color, establish minimum and maximum expected values for each color channel.
static constexpr char colorList[colorAmount + 1] = {"NAG"}; // List of color initials
// Each row represents the upper and lower limits for detecting a color.
// colorThresholds[0] = {redMin, redmax, greenMin, greenMax, blueMin, blueMax}
static constexpr int colorThresholds[colorAmount][6] = {
{0, 40, 0, 40, 0, 40},
{60, 100, 120, 150, 125, 175},
{180, 240, 190, 210, 180, 210}};
-
After each reading, check if the values are within the expected range for each color.
-
Return a value indicating a specific color if all three channels match the expected range.
char TCS::getColorWithThresholds()
{
if (colorThresholds == nullptr)
return 'u';
updateRGBC(); // Update the RGB values
for (uint8_t i = 0; i < colorAmount; i++) {
if (inRangeThreshold(colorThresholds[i][0], red, colorThresholds[i][1]) && inRangeThreshold(colorThresholds[i][2], green, colorThresholds[i][3]) && inRangeThreshold(colorThresholds[i][4], blue, colorThresholds[i][5])){
return colorList[i];
}
}
return 'u'; // In case no color is detected.
}