I know, it's complicated.
So you need to as your self. What is red?
Red is when the reflected light coming off an object is MOSTLY red. Not completely red. You will never have only red reflected off an object.
So red is when the red reading is much higher than the blue and green. So you look at the red, the blue and the green and you say that if the red is over 100 (just a random number you will have to mess with it) and the blue/green are both under 50.... Well that must be red!
BUT... If you need to test for magenta for instance, that would be when the red and blue are both high, but a very low green.
Green is when only green is high.
And so on.
Color is CRAZY weird. I once wrote an essay on the color white. White is the most complicated of them all.
But you need to train your robot by picking up a brick shove it in the face of the sensor, and write down what the reading is.
Then figure out a way to check if that reading is close to that.
If it is... bam... it's the same color!
So you could say that a red brick reads at (I have no clue) 150, 34, 47.
So you could do something like this to see if the colors are within a tolerance (you need to choose this) of what you expected, you are good.
if abs(readRed - expectedRed) < tolerance) you are good
if abs(readBlue - expectedBlue) < tolerance) you are good
if abs(readGreen - expectedGreen) < tolerance) you are good
Perri wrote:Hey, thanks for the reply, but we really dont understand anything of that code..