Color Sensing with TCS3200, Need Help with Code & Understanding

Johan_Ha:
I have no idea of what the frequencies mean. But B= -153 is just plain wrong. The analogWrite() writes values from 0 to 255. That's one unsigned byte. Whatever you put there will be treated as an unsigned byte. -153 is a signed number that needs more than 8 bits. Passing it to the analogWrite() will just pass 8 bits. The value passed is 01100111 or 103. Doing writeAnalog(-153) will equal analogWrite(103).

If frequency 25 means full blue colour and frequency 70 means zero blue colour, then your original mapping function is correct. But do as I told you to. If the map function returns values outside the 0 - 255 range, you must adjust the value to 0 or 255. Why it goes beyond the range is beyond me. Instead of adjusting to the range, perhaps you could re-read the sensor until you get sane values.

Thank you, I'll try these out, and will let you know what happens.

I've been wondering something else too, but I can't find much info online.

I want the LED to turn off, if the sensor isn't detecting any color. (For example, if I take the sensor off of the colored paper, it will push a bunch of negative values that are like -1800 and such. During this, the LED is a yellowish green color.)

Instead of the LED being ON in this situation, I'd like it to be turned off. So that it only turns on when there's "sane values" detected by the sensor (such as when it's placed against a colored piece of paper).

Do you know how I could do this?