Color Sensing with TCS3200, Need Help with Code & Understanding

Change this:

  // 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;

...to this:

  // 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
  bcolor = map(frequency, 25,70,255,0);

This is just for clarity. Let the frequency variable hold the frequency value . Don't change that variable to anything else. Instead use bcolor for the converted value.

That won't correct the harmful negative values. The map function will return a negative value, if the frequency goes (due to faulty reading from the sensor?) over the upper limit. The map function doesn't automatically restrict the values to the 0 - 255 interval.