How do I identify more colors, using a color sensor?

I was directed to a tutorial online that helped me figure out how to detect colors, but the tutorial doesn't use the rgb format, he uses percentages.

This now makes it difficult for me to figure out how to create different colors, e.g. brown and yellow

The code can be found here

/*
reibot.org 
Demo program for TCS3200 from parallax and the parallax daughterboard 

Call detectColor(out) where 'out' is pinC on the daughterboard. The detectColor will return a 0 if there is nothing color in front of sensor,
1 if red is in front, 2 if blue is in front, or 3 if blue is in front. You can comment out all the serial.print. 

If you're tight on pins, remove the taosMode(int) method and all references to it. Remove pins from the TCS3200setup too.
If these wires are disconnected the TCS3200 will run on the highest frequency due to internal pullup resistors on S0 and S1 

If you have multiple TCS3200 you may tie all the pins together except the outputs (pinC). Then just use detectColor(TCS3200's output) to 
detect color on the selected TCS3200's output pin. 

7/6/2011 works on arduino 0022

Taos pins connect to arduino pins 8-13. There is no order and should work on any digital i/o
*/


int S0 = 40; //pinB
int S1 = 37; //pinA
int S2 = 41; //pinE
int S3 = 39; //pinF
int out = 38; //pinC
int LED = 36; //pinD

void setup()
{
  TCS3200setup();
  Serial.begin(115200);
  Serial.print("\n\n\nready\n\n\n");
  delay(100);
}

void loop()
{
  Serial.print(detectColor(out));
  Serial.print("\n\n\n");
  delay(1000);
}

int detectColor(int taosOutPin)
{
  //isPresentTolerance will need to be something small if used in high light environment, large if used in dark environment.
  //the color detection will work either way, but the larger isPresentTolerance is, the closer the object will need to be in front of sensor
  
  double isPresentTolerance = 5;
  double isPresent = colorRead(taosOutPin,0,0)/colorRead(taosOutPin,0,1);

  //number gets large when something is in front of sensor. 
  Serial.print("isPresent:");
  Serial.println(isPresent,2);
  Serial.print("isPresentTolerance currently set to:");
  Serial.println(isPresentTolerance,2);

  if(isPresent < isPresentTolerance)
  {
    Serial.println("nothing is in front of sensor");
    
    return 0;
  }

  double red,blue,green;
  double white = colorRead(taosOutPin,0,1);

  red = white / colorRead(taosOutPin,1,1);
  blue = white / colorRead(taosOutPin,2,1);
  green = white / colorRead(taosOutPin,3,1);
  
  Serial.print("red");
  Serial.println(red);
  Serial.print("blue");
  Serial.println(blue);
  Serial.print("green");
  Serial.println(green);

  if(red > blue && red > green)
  {
    Serial.println("red is in front");
    return 1;
  }
  
  if(blue > green && blue > red)
  {
    Serial.println("blue is in front");
    return 2;
  }
  
  if(green > blue && green > red)
  {
    Serial.println("green is in front");
    return 3;
  }
}

/*
This method will return the pulseIn reading of the selected color.

Since frequency is proportional to light intensity of the selected color filter, 
the smaller pulseIn is, the more light there is of the selected color filter.
  
It will turn on the sensor at the start taosMode(1), and it will power off the sensor at the end taosMode(0)

color: 0=white, 1=red, 2=blue, 3=green

if LEDstate is 0, LED will be off. 1 and the LED will be on.

taosOutPin is the ouput of the TCS3200. If you have multiple TCS3200, all wires can be combined except the out pin
*/

double colorRead(int taosOutPin,int color,boolean LEDstate)
{
  //make sure that the pin is set to input
  pinMode(taosOutPin,INPUT);
  
  //turn on sensor with highest frequency setting
  taosMode(1);
  
  //delay to let the sensor sit before taking a reading. Should be very small with this sensor
  int sensorDelay = 1;
  
  //set the pins to select the color  
  if(color == 0){
    //white
    digitalWrite(S3,LOW);//S3
    digitalWrite(S2,HIGH);  //S2
    // Serial.print(" w");
  }

  else if(color == 1)
  {
    //red
    digitalWrite(S3,LOW); //S3
    digitalWrite(S2,LOW); //S2
    // Serial.print(" r");
  }

  else if(color == 2)
  {
    //blue
    digitalWrite(S3,HIGH);  //S3
    digitalWrite(S2,LOW); //S2 
    // Serial.print(" b");
  }
      
  else if(color == 3)
  {
    //green
    digitalWrite(S3,HIGH);  //S3
    digitalWrite(S2,HIGH);  //S2 
    // Serial.print(" g");
  }

  double readPulse;

  if(LEDstate == 0)
  {
    digitalWrite(LED,LOW);
  }
  
  if(LEDstate == 1)
  {
    digitalWrite(LED,HIGH);
  }

  delay(sensorDelay);
  
  readPulse = pulseIn(taosOutPin,LOW,80000);
  
  //if the pulseIn times out, it returns 0 and that throws off numbers. just cap it at 80k if it happens
  if(readPulse < .1)
  {
    readPulse = 80000;
  }
  
  //turn off color sensor and white LED to save power 
  taosMode(0);

  return readPulse;
}

//setting mode to zero will put taos into low power mode. taosMode(0);
void taosMode(int mode)
{
  if(mode == 0)
  {
    //power OFF
    digitalWrite(LED,LOW);
    digitalWrite(S0,LOW); //S0
    digitalWrite(S1,LOW); //S1
    
    // Serial.println("mOFFm");
  }
  
  else if(mode == 1)
  {
    //this will put in 1:1
    digitalWrite(S0,HIGH);  //S0
    digitalWrite(S1,HIGH);  //S1

    // Serial.println("m1:1m");
  }
  
  else if(mode == 2)
  {
    //this will put in 1:5
    digitalWrite(S0,HIGH); //S0
    digitalWrite(S1,LOW);  //S1

    //Serial.println("m1:5m");
  }
  
  else if(mode == 3)
  {
    //this will put in 1:50
    digitalWrite(S0,LOW); //S0
    digitalWrite(S1,HIGH);  //S1
     
    //Serial.println("m1:50m");
  }
  
  return;
}

void TCS3200setup()
{
  //initialize pins
  pinMode(LED,OUTPUT);  //LED pinD
  
  //color mode selection
  pinMode(S2,OUTPUT); //S2 pinE
  
  pinMode(S3,OUTPUT); //s3 pinF
  
  //color response pin (only actual input from taos)
  //pinMode(out, INPUT); //out pinC
  //communication freq output divider
  pinMode(S0,OUTPUT); //S0 pinB
  pinMode(S1,OUTPUT); //S1 pinA 
  
  return;
}

and a summary of the code here

Please let me know, if it would be preferred to post the code rather than a link to it..

Please help..

Most forum members prefer not to go off-site to look at code. You will likely get more help if you do post the code here.

thanks much @wildbill

There is some missing code that would be wonderful to see to lend a hand in getting a better handle on what's going on.

It looks like there is a tri-color LED connected to the pins of some uController that gets set in relation to the color selected, correct?

So if you have a 3 color LED with pins R, G, and B and you are just setting the pin combinations to get colors, you'll want to add new pin combinations to

  digitalWrite(LED,LOW);
    digitalWrite(S0,LOW); //S0
    digitalWrite(S1,LOW); //S1

LED (R) 0, 1, 0, 1, 0, 1, 1
SO (G) 0, 0, 1, 1, 0, 0, 1
S1 (B) 0, 0, 0, 0, 1, 1, 1

Which pins are RGB is just my guess.

0,0,0 = all off
1,0,0 = red
0,1,0 = green
0,0, 1 = blue

1, 1, 0 = yellow
1, 0, 1 = pink
1, 1, 1 = white

@Idahowalker thanks for your reply..

I've psted all the code, so if you wan give it a look again.

Your answer makes alot of sense to be honest, I'm gonna try it..

Based on the code, I found:

110: white
100: Red
101: Red
111" Green

Still can't figure it out.

Can I get more help or guidance, please?