// TCS230/TCS3200 Color Sensor
// connect EO to GND
#define S0 4
#define S1 5
#define S2 6
#define S3 7
#define OUT 8
int frequency = 0;
void setup() {
Serial.begin(9600);
pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(OUT, INPUT);
// Output Frequency Scaling
// S0 S1 Scaling
// Low Low Power down
// Low High 2%
// High Low 20%
// High High 100%
digitalWrite(S0,HIGH);
digitalWrite(S1,LOW);
}
void loop() {
// Setting photodiode filter color
// S2 S3 Color
// Low Low Red
// Low High Blue
// High Low Clear (no filter)
// High High Green
// Setting red filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,LOW);
// Reading the output frequency
frequency = pulseIn(OUT, LOW);
//Remaping the value of the frequency to the RGB Model of 0 to 255
//frequency = map(frequency, 25,72,255,0);
Serial.print("R=");
Serial.print(frequency);
delay(100);
// Setting Green filtered photodiodes to be read
digitalWrite(S2,HIGH);
digitalWrite(S3,HIGH);
// Reading the output frequency
frequency = pulseIn(OUT, LOW);
//Remaping the value of the frequency to the RGB Model of 0 to 255
//frequency = map(frequency, 30,90,255,0);
Serial.print(" G=");
Serial.print(frequency);
delay(100);
// Setting Blue filtered photodiodes to be read
digitalWrite(S2,LOW);
digitalWrite(S3,HIGH);
// Reading the output frequency
frequency = pulseIn(OUT, LOW);
//Remaping the value of the frequency to the RGB Model of 0 to 255
//frequency = map(frequency, 25,70,255,0);
Serial.print(" B=");
Serial.print(frequency);
delay(100);
// Setting Clear filtered photodiodes to be read
digitalWrite(S2,HIGH);
digitalWrite(S3,LOW);
// Reading the output frequency
frequency = pulseIn(OUT, LOW);
//Remaping the value of the frequency to the RGB Model of 0 to 255
//frequency = map(frequency, 25,70,255,0);
Serial.print(" C=");
Serial.println(frequency);
delay(100);
}