is was giving good results, until i changed something, it was 12am and i was really sleepy !
well first, i was looking somewhere and i tough, each colored object reflects its own color light better ! i went to try this and saw yes ! but knew for sure a lot of people tough of this already xD
i made this code
:
int CN[3]; // holds each color result
int blue = 11, green = 12, red = 13; // just to dont get messy !
void swap(int,int);
void setup(){
Serial.begin(9600);pinMode(13,OUTPUT);
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
}void loop(){
digitalWrite(green,HIGH);
delay(15);
CN[0] = analogRead(0);
digitalWrite(green,LOW);digitalWrite(blue,HIGH);
delay(15); // delay for RBG LED to get its full brightness
CN[1] = analogRead(0); // reads photoresistor while the blue led is on (must see more light if object is blue);
digitalWrite(blue,LOW); // turn off for next colordigitalWrite(red,HIGH);
delay(15);
CN[2] = analogRead(0);
digitalWrite(red,LOW);/if(CN[0] > CN[1] && CN[0] > CN[2]){
Serial.println("Green!");
} else
if(CN[1] > CN[0] && CN[1] > CN[2]){
Serial.println("Blue!");
} else {
if(CN[2] > CN[0] && CN[2] > CN[1]){
Serial.println("Red!");
}
}/
Serial.print("Green: ");
Serial.println(CN[0]);
Serial.print("Blue: ");
Serial.println(CN[1]);
Serial.print("Red: ");
Serial.println(CN[2]);
Serial.println(" ------------------- END");delay(2000); // time to read and think !
}/void swap(int a, int b)
{
temp = a;
a = b;
b = temp;
}/
it always give me Green ! but when i put my finger or a red colored object it shows red ! is shows green when theres nothing on top of it!
it shows green still even when a blue object is on top of it !
here are results on console:
nothing on front :
Green: 235
Blue: 194
Red: 199
------------------- END
red object on front:
Green: 125
Blue: 86
Red: 220
blue object on front:
Green: 304
Blue: 269
Red: 184
---------
green object:
Green: 419
Blue: 196
Red: 280
------------------- END
I just puted a phororesistor and a rbg led next to it !