I’m working on a project where kids can hold a piece of paper up to one of Adafruit’s color sensor breakout boards (triggered to take a reading from an IR sensor) which lights up a frosted orb.
It’s all working well enough but I wish the colors were more saturated. For example a red sheet of paper creates a pink orb, a blue piece of paper a pale blue orb, etc.
I think I need to convert my values to HSV but I’m not having any luck adjusting my own code.
Does anyone know if there’s a way to juice up the saturation in the code? Under a bit of a tight deadline here…I might just have to live with it but this would be way better if I could get the LED colors closer to the paper colors
int irSensor=14;
int Led=11;
int senRead=0;
int SenseRate=900; // higer numbers are more sensitive ir sensor
// Include the libraries:
#include <Wire.h>
#include <Adafruit_TCS34725.h>
#include <FastLED.h>
// Define variables:
float r, g, b;
#define NUM_LEDS 24
#define BRIGHTNESS 150
// Define connections:
#define DATA_PIN 6
CRGB leds[NUM_LEDS];
// Initialise with specific int time and gain values:
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_154MS, TCS34725_GAIN_4X); // integreation times can be 2_4MS, 24MS, 50MS, 101MS, 154MS, 700MS -gain can be 1X, 4X, 16X, 60X
void setup()
{
pinMode(irSensor,INPUT);
pinMode(Led,OUTPUT);
digitalWrite(irSensor,HIGH);
digitalWrite(Led,HIGH);
Serial.begin(9600);
// Begin Serial communication:
Serial.begin(9600);
// Check if the sensor is wired correctly:
if (tcs.begin()) {
Serial.println("Found sensor");
} else {
Serial.println("No TCS34725 found ... check your connections");
while (1);
}
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
}
void loop()
{
int val=analogRead(senRead);
Serial.println(val);
if(val <= SenseRate)
{
digitalWrite(Led,HIGH); //spotlight
delay(500); // spotlight time on
// Get calculated RGB values:
tcs.getRGB(&r, &g, &b);
// Convert to integers:
int red = (int)r;
int green = (int)g;
int blue = (int)b;
// Print the data to the Serial Monitor:
Serial.print(red); Serial.print(" "); Serial.print(green); Serial.print(" "); Serial.println(blue);
CRGB color = CRGB(red, green, blue);
// Set all the LEDs to the measured color:
fill_solid(leds, NUM_LEDS, color);
FastLED.show();
digitalWrite(Led,LOW);
delay(2000);
}
else if(val > SenseRate)
{
digitalWrite(Led,LOW);
delay(20);
}
}