#include <Adafruit_TCS34725.h>
#include <Servo.h>
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS,TCS34725_GAIN_4X);
Servo miservo;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
tcs.begin();
miservo.attach(9);
}
void loop() {
// put your main code here, to run repeatedly:
float red,green,blue;
tcs.getRGB(&red,&green,&blue);
int R = int(red);
int G = int(green);
int B = int(blue);
String color = "";
if((R-G>50)&(R-B>50)){
color = "Red";
miservo.write(30);
}
if((G-B>10)&(G-R>30)){
color = "Green";
miservo.write(90);
}
if ((B-G>20)&(B-R>40)){
color = "Blue";
miservo.write(150);
}
if ((R-B>40)&(G-B>40)){
color = "Yellow";
}
Serial.print("R: ");Serial.print(int(red));
Serial.print(" G: ");Serial.print(int(green));
Serial.print(" B: ");Serial.print(int(blue));
Serial.print(" Color: ");Serial.print(color);
Serial.println();
}