Hi all.
I have been playing with the I2C TCS3472 colour sensor tonight (connected to an UNO).
I was hoping to get the detector to match the detected colour to output on an RGB strip using Fastled.
I have the sensor in a small white enclosure for testing, with an RGB led inside the enclosure that reflects off the top of the box (not pointing directly at the TCS3472.
I have also disabled the onboard white led on the TCS3472, as I don't appear to need it.
I have had REAL trouble finding a library that actually compiles without errors. None of them appear to output what I need.
My hastily assembled to efforts are below, but they don't track the colour very well. Yellow is definitely a colour it has problems with. Individual colours (red, green and blue) are fine.
Anyone achieved this?
#include <Wire.h>
#include "Adafruit_TCS34725.h"
#include <FastLED.h>
#define DATA_PIN 3 // Data to the addressable WS2812 leds
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS 1
CRGB leds[NUM_LEDS];
#define BRIGHTNESS 255
#define FRAMES_PER_SECOND 120
float red, green, blue;
// our RGB -> eye-recognized gamma color
byte gammatable[256];
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);
void setup() {
Serial.begin(9600);
Serial.println("RGB Colour detection system");
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1); // halt!
}
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); // Setup the addressable leds
delay(500);
FastLED.setBrightness(255);
}
void loop() {
tcs.getRGB(&red, &green, &blue);
Serial.print("R:\t"); Serial.print(int(red));
Serial.print("\tG:\t"); Serial.print(int(green));
Serial.print("\tB:\t"); Serial.println(int(blue));
Serial.println("");
for ( int i = 0; i < NUM_LEDS; i++) {
//leds[i].setRGB( gammatable[(int)red], gammatable[(int)green], gammatable[(int)blue]);
leds[i].setRGB((int)red, (int)green, (int)blue);
//leds[i].setRGB(0, 255, 0);
FastLED.show(); // send the 'leds' array out to the actual LED strip
}
delay(300);
}
Several attempts at the Fastled output there. What does the 'gammatable' bit do?
I also tried:
include "TCS34725.h"
#include <FastLED.h>
TCS34725 tcs;
#define DATA_PIN 3 // Data to the addressable WS2812 leds
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS 1
CRGB leds[NUM_LEDS];
#define BRIGHTNESS 255
#define FRAMES_PER_SECOND 120
void setup(void)
{
Serial.begin(115200);
Wire.begin();
if (!tcs.attach(Wire))
Serial.println("ERROR: TCS34725 NOT FOUND !!!");
tcs.integrationTime(33); // ms
tcs.gain(TCS34725::Gain::X01);
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); // Setup the addressable leds
delay(500);
FastLED.setBrightness(255);
}
void loop(void)
{
if (tcs.available())
{
static uint32_t prev_ms = millis();
TCS34725::Color color = tcs.color();
Serial.print("Interval : "); Serial.println(millis() - prev_ms);
Serial.print("Color Temp : "); Serial.println(tcs.colorTemperature());
Serial.print("Lux : "); Serial.println(tcs.lux());
Serial.print("R : "); Serial.println(color.r);
Serial.print("G : "); Serial.println(color.g);
Serial.print("B : "); Serial.println(color.b);
TCS34725::RawData raw = tcs.raw();
Serial.print("Raw R : "); Serial.println(raw.r);
Serial.print("Raw G : "); Serial.println(raw.g);
Serial.print("Raw B : "); Serial.println(raw.b);
Serial.print("Raw C : "); Serial.println(raw.c);
prev_ms = millis();
for ( int i = 0; i < NUM_LEDS; i++) {
//leds[i].setRGB( gammatable[(int)red], gammatable[(int)green], gammatable[(int)blue]);
//leds[i].setRGB((int)red, (int)green, (int)blue);
leds[i].setRGB(color.r, color.g, color.b);
FastLED.show(); // send the 'leds' array out to the actual LED strip
}
}
delay(300);
}
Just wondered if anyone has any suggestions or pointers to better code?