#include <EasyColor.h>
//TCS3200 pins wiring to Arduino
#define s0 4
#define s1 5
#define s2 6
#define s3 7
#define outPin 8
#define btLED 13
// Variables
int red;
int green;
int blue;
int tempr = 0;
int tempg = 0;
int tempb = 0;
int maxr = 300;
int lowr = 0;
int maxg = 360;
int lowg = 0;
int maxb = 260;
int lowb = 0;
//Make sure to install EasyColor library from Sketch -> Include Library
hsv out_hsv;
rgb in_rgb;
rgb nrgb;
EasyColor::HSVRGB HSVConverter;
void setup()
{
pinMode(s0, OUTPUT);
pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, OUTPUT);
pinMode(outPin, INPUT); //out from sensor becomes input to arduino
pinMode(btLED, INPUT);
//setting the output frequency at 20%
digitalWrite(s0, HIGH);
digitalWrite(s1, LOW);
Serial.begin(9600);
}
void loop()
{
readRGB();
//You should use and tweak the values until you think you have a more accurate read
//Then you use the nrgb to print the values
// /*
out_hsv = HSVConverter.RGBtoHSV(in_rgb, out_hsv);
out_hsv.s = out_hsv.s +20;
if(out_hsv.s > 100){
out_hsv.s = 100;
}
nrgb= HSVConverter.HSVtoRGB(out_hsv,nrgb)
// String msg = “{‘format’:’rgb’,’r’:” + String(in_rgb.r) + “,’g’:” + String(in_rgb.g) + “,’b’:” + String(in_rgb.b) + “}!”;
String msg = “{‘format’:’rgb’,’r’:” + String(nrgb.r) + “,’g’:” + String(nrgb.g) + “,’b’:” + String(nrgb.b) +”}!”;
Serial.println(msg);
Serial.flush();
delay(300);
}
/* read RGB components */
void readRGB() {
/*
Each digitalWrite values correlate to the RGB that is followed by
Depending on the values you get from pulseIn without the
conditions and map(), you should change the ‘temp’ varialbes
and (un)comment the conditions as you need
*/
digitalWrite(s2, LOW);
digitalWrite(s3, LOW);
tempr = pulseIn(outPin, LOW);
if (tempr > maxr) {
tempr = maxr;
}/* else if(tempr < lowr){
tempr = lowr;
}*/
tempr = map(tempr, lowr, maxr, 255, 0);
digitalWrite(s2, HIGH);
digitalWrite(s3, HIGH);
tempg = pulseIn(outPin, LOW);
if (tempg > maxg) {
tempg = maxg;
}/* else if(tempg < lowg){
tempg = lowg;
}*/
tempg = map(tempg, lowg, maxg, 255, 0);
digitalWrite(s2, LOW);
digitalWrite(s3, HIGH);
tempb = pulseIn(outPin, LOW);
if (tempb > maxb) {
tempb = maxb;
}/* else if(tempb < lowb){
tempb = lowb;
}*/
tempb = map(tempb, lowb, maxb, 255, 0);
in_rgb.r = tempr;
in_rgb.g = tempg;
in_rgb.b = tempb;
}