How do I integrate that in my program, I just need to make a function like isGreen(); and return HIGH if green, I am not asking you to make the function and share it (I´ll appreciate if you do that) but I´m really looking forward to understand how it works
Thank you, but what I don't understand is the interrupts, maybe that's just i2c basics but I'm really hurried because we have 4 day to finish our robot and Between the shoot and homeworks I don't have enough time to learn i2c, or dou you know an easy explanation?
I'm thinking in making a function isGreen( ) an inside the function place the example code the part that is inside of if (colorAvailable) {} and add some stuff to check if green is higher than red and blue, but I don't know is if the function readGData() returns any other thing than a Word variable, or how can I get a value from 0 to 255
Magdiel:
but I don't know is if the function readGData() returns any other thing than a Word variable, or how can I get a value from 0 to 255
Do you know what a word is? Read the documentation on the sensor, what is the maximum value that will spit out? Scaling that down to 255 should just be a matter of division (or a bitshift if you're smart).
My values of 0 to 255 were just an arbitrary example.
I don't have the particular piece of hardware that you do. So I can't comment on exactly what values get returned in the word data type from that function e. readGData
Regardless of that, I doubt that your simplistic approach of just comparing green to red and green to blue will work without defining a threshold e.g. An relative offset between green and red or green and blue
E.g.
I doubt your eye would perceive. A RGB colour of 128,129,128 as green, even though the green channel is higher , you would see this as grey
Colour perception theory is a science in its own right, but if collect enough data you can probably work out an algorithm for the things you want to measure
And how can I transform a word variable to a value from 0 to 255 to make the decisions easier for me, because it gives me big values, how can I convert them to an hex color value like ff0033 or something like that?
I need to check if the sensor is over something green, but after checking it over a variety of object but I don´t see any major difference in the values from blue and green. And I don't understand those values and I´d like to see them in a range from 0 to 255 to plot them or vie a color generation and use those values, then see what is the color the sensor detected in a graphic way
This are the values that it throws when I placed the sensor like 2 or 3 cm above a yellow Post-It (Image attached) end when i place the RGB values in an Hex to RGB converter it says its kind of brown and when I repeat that process over a white plastic table, a blue pencil box and the greenish Arduino box it is always a brown color
Are you missing something like a lens to focus the image into the sensor?
What lighting are you using, sunshine, or indoor lighting , you will not get good results using light from sources like low energy lamps as they don’t have the full spectrum of light.
Btw. You can cut and paste text from the serial window. Screen grabs are not that helpful
You should collate you data which you cut from the serial window into a spreadsheet