Stopping rgb sensor(tcs34725) at specific rgb value

Hello,
I am a college student who encountered Arduino for the first time this semester. I'm applying the code I've learned to present an assignment, but I'm having a problem.
I'm trying to make a code with arduion uno to stop the tcs34725 rgb sensor at specific rgb value(R:47~48,G:89~90,B:99~100). Therefore I tried to use if but the error doesn't go away. I want to know that is it possible to stop sensor, and if it's possible, please help me to know the exact code to realize it.

#include <Wire.h>
#include <Adafruit_TCS34725.h>
#define redpin 3 
#define greenpin 5
#define bluepin 6
#define commonAnode true
byte gammatable [256];
Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS,TCS34725_GAIN_4X);
void setup() {
  Serial.begin(9600);
  if (tcs.begin()){
  } else {
    Serial.println("NO TCS34725 found ... check your connections");
    while (1);
  }
#if defined (ARDUINO_ARCH_ESP32)
 ledAttachPin (redpin, 1);
 ledSetup(1, 12000, 8);
 ledAttachPin (greenpin, 2);
 ledSetup(2, 12000, 8);
 ledAttachPin ( bluepin, 3);
 ledSetup(3, 12000, 8);
#else
  pinMode(redpin, OUTPUT);
  pinMode(greenpin, OUTPUT);
  pinMode(bluepin, OUTPUT);
#endif
  for (int i=0; i<256; i++) {
  float x = i;
  x /= 255;
  x = pow(x, 2.5);
  x *=255;
  if (commonAnode) {
    gammatable[i] = 255-x;
  } else {
    gammatable[i] = x;
  }
  }
}
void loop () {
  float red,green,blue;
  tcs.setInterrupt(false);
  delay(1000);
  tcs.getRGB(&red, &green, &blue);
  tcs.setInterrupt(true);
  Serial.println("R:\t"); Serial.print(int(red));
  Serial.println("\tG:\t"); Serial.print(int(green));
  Serial.println("\tB:\t"); Serial.print(int(blue));
  Serial.print("\n");
#if defined(ARDUINO_ARCH_ESP32)
  ledWrite(1, gammatable[(int)red]);
  ledWrite(2, gammatable[(int)green]);
  ledWrite(3, gammatable[(int)blue]);
#else
  analogWrite(redpin, gammatable[(int)red]);
  analogWrite(greenpin, gammatable[(int)green]);
  analogWrite(bluepin, gammatable[(int)blue]);
#endif
#if (47<red<48, 89<green<90, 99<blue<100) {
 tcs.setInterrupt(true);
}
}

Error code is below

C:\Users\ASUS\Documents\Arduino\RGB\RGB.ino:59:43: error: token "{" is not valid in preprocessor expressions
 #if (47<red<48, 89<green<90, 99<blue<100) {
                                           ^
C:\Users\ASUS\Documents\Arduino\RGB\RGB.ino:59:0: error: unterminated #if
 #if (47<red<48, 89<green<90, 99<blue<100) {

Compilation error: token "{" is not valid in preprocessor expressions

Not following you at all. How do you "stop a sensor"? If you don't want sensor data, you can just leave it alone and don't take any readings from it.

Probably that is not what you mean, but it's not clear what you do mean.

By "if", do you mean "an 'if' statement"? If so, you need to tell us whether you posted a sketch with, or without it. And, explain the implications of that.

This is "a flock of seagulls" style formatting. Unless you can produce tidy indentation yourself, you should use ctrl-T in the IDE to autoformat the code.

The above not is valid format for an if statement, and contains the rather dangerous comma operator.

Did you intend something like this?

if (47<red and red<48 and 89<green and green<90 and 99<blue and blue<100) {

Since red, green and blue are floats, it would be clearer if you wrote

if ( (47.0<red and red<48.0) and (89.0<green and green<90.0) and (99.0<blue and blue<100.0) ) {
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.