Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
Please post a schematic.
Please post an image of your project.
Please describe the problem better then you just did.
It sounds to me like you want to search for the RGB PWM settings that will produce a particular color as seen by the color sensor. I think this will get you close.
void loop() {
static int redPWM = 0, greenPWM = 0, bluePWM = 0;
float red, green, blue;
tcs.getRGB(&red, &green, &blue);
// R 47~48, G 89~90, B 99~100.
if (red < 47.0)
redPWM++;
if (red > 48.0)
redPWM--;
if (green < 89.0)
greenPWM++;
if (green > 90.0)
greenPWM--;
if (blue < 99.0)
bluePWM++;
if (blue > 100.0)
bluePWM--;
Serial.print("Red: ");
Serial.print(red);
Serial.print(" PWM: ");
Serial.print(redPWM);
Serial.print("\tGreen: ");
Serial.print(green);
Serial.print(" PWM: ");
Serial.print(greenPWM);
Serial.print("\tBlue: ");
Serial.print(blue);
Serial.print(" PWM: ");
Serial.println(bluePWM);
#if defined(ARDUINO_ARCH_ESP32)
ledWrite(1, redPWM);
ledWrite(2, greenPWM);
ledWrite(3, bluePWM);
#else
analogWrite(redpin, redPWM);
analogWrite(greenpin, greenPWM);
analogWrite(bluepin, bluePWM);
#endif
}