Color Sensing with TCS3200, Need Help with Code & Understanding

I'll give that a shot! That's what I've been trying to do, just not sure exactly how to do that. I've tried using the integer of "frequency" because thats what seems to be used to set those numbers, but maybe it's not.

I'll keep messing around with it. I found some code online that does work properly, but it's not efficient and not so good for my sensor. So I really want to get this one working.

EDIT:

Awesome, I think I got it, kinda! It's not so accurate, and sometimes I get negative results (like R -382), could you check?

What I changed was, setting a int for each corresponding color (R,G,B) and making that equal the frequency before the frequency is used to detect another color. Then I've set the analogwrite to write that number to the pin.

What I think I need to do next is: 1) Calibrate the sensor so its more accurate. 2) Find some way to remove the negative numbers (so it is just from 0 to 255), and 3) Turn off RGB LED if it's not detecting anything (or if it detects the same "environmental color data" for an extended period of time.).

I'd appreciate some tips and feedback on how to do that.

For some reason, even when scanning a green or blue, etc color object, the red LED is on as well. Not sure why. As the number for the red would be low (like negatives actually in terminal), so the pin shouldnt be getting any data. Maybe I need to get rid of these negative values...

#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define sensorOut 8
#define RGBLEDR 10
#define RGBLEDG 11
#define RGBLEDB 12

int frequency = 0;
int rcolor;
int gcolor;
int bcolor;

void setup() {
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(sensorOut, INPUT);
pinMode(RGBLEDR, OUTPUT);
pinMode(RGBLEDG, OUTPUT);
pinMode(RGBLEDB, OUTPUT);

// Setting frequency-scaling to 20%
digitalWrite(S0,HIGH);
digitalWrite(S1,LOW);

Serial.begin(9600);
}
void loop() {
// Setting red filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
//Remaping the value of the frequency to the RGB Model of 0 to 255
frequency = map(frequency, 25,72,255,0);
rcolor = frequency;
//LEDColor(frequency,frequency,frequency);
// Printing the value on the serial monitor
Serial.print("R= ");//printing name
Serial.print(frequency);//printing RED color frequency
Serial.print(" ");
delay(300);
// Setting Green filtered photodiodes to be read
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
//Remaping the value of the frequency to the RGB Model of 0 to 255
frequency = map(frequency, 30,90,255,0);
gcolor= frequency;
// LEDColor(frequency,frequency,frequency);
// Printing the value on the serial monitor
Serial.print("G= ");//printing name
Serial.print(frequency);//printing GREEN color frequency
Serial.print(" ");
delay(300);
// Setting Blue filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
// Reading the output frequency
frequency = pulseIn(sensorOut, LOW);
//Remaping the value of the frequency to the RGB Model of 0 to 255
frequency = map(frequency, 25,70,255,0);
bcolor = frequency;
// LEDColor(frequency,frequency,frequency);
// Printing the value on the serial monitor
Serial.print("B= ");//printing name
Serial.print(frequency);//printing BLUE color frequency
Serial.println(" ");
delay(300);

analogWrite(RGBLEDR,rcolor);
analogWrite(RGBLEDG,gcolor);
analogWrite(RGBLEDB,bcolor);

}