Color Sensor not detecting accurately

My right color sensor isn’t working. Can someone help?
I am using Vexcode IQ,
It isn’t detecting the colors that it is supposed to detect.
Please reply fast. It is urgent

My robot:
https://lh3.googleusercontent.com/U40_wL58ni90OwoHDmIsBko1TEi4nxVOyu19RVvcH8PvxZE33L-vemCacXqThNAA_NK8bG0MjCKfGubxlCIn9Q4FMj1ZgEUNQuFyLYza96h0cXIsLVNglzMntt6yaoT0R50sTxikS-foaOcD8pg5jm0vs4TN19cFWT9AHqshqno2G3oOqMpUoY50M6eDCGEox5a_q0xw2wHR=w1920-h1014

My robot configuration:
https://lh3.googleusercontent.com/32I2Kh0-rFnjJRXs66hThHYly074HinGyo8EFEgecb0CkIotRISh8DdjSOfzMXgPE1q5qQuUllihOiKkyykPyGJ1Z_cXh5yMS9YpHwFqBSag1J3nVFgdV83_KdADzE3dTAaqEFT8_syQz5Bi8B-t-vDoKYi9nU2dRQMlabhI_NY4PXqOUmusnehMMfD-Q9m95eYLF7oVKAGx=w1920-h1014

My code is here:

float myVariable;

event message1 = event();
event SETtimer = event();
event message2 = event();
event message3 = event();
event message4 = event();
event message5 = event();
event message6 = event();
event message7 = event();

// "when started" hat block
int whenStarted1() {
  // does not allow more than 3 when started blocks, so i did this
  while (true) {
    message1.broadcast();
    message2.broadcast();
  wait(20, msec);
  }
  return 0;
}

// "when started" hat block
int whenStarted2() {
  while (true) {
    BelowColor.setLight(86, percent);
    FrontColor.setLight(60, percent);
    LeftTouchLED.setFade(slow);
    RightTouchLED.setFade(slow);
    LeftTouchLED.setBrightness(100);
    RightTouchLED.setBrightness(100);
  wait(20, msec);
  }
  return 0;
}

// "when started" hat block
int whenStarted3() {
  return 0;
}

// "when I receive message2" hat block
void onevent_message2_0() {
  while (true) {
    if (BelowColor.detects(colorType::none)) {
      // this says that if no color is detected, play this "random" loop
      RightTouchLED.setColor(red);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(red_violet);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(red_orange);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(orange);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(yellow_orange);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(white);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(yellow);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(yellow_green);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(green);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(blue_green);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(blue);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(blue_violet);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(violet);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
      RightTouchLED.setColor(purple);
      wait(0.25, seconds);
      RightTouchLED.setFade(slow);
    }
    else {
      // this says if "x" color detected, show color "x" on the touch led right
      if (BelowColor.detects(red)) {
        RightTouchLED.setColor(red);
      }
      else {
        if (BelowColor.detects(green)) {
          RightTouchLED.setColor(green);
        }
        else {
          if (BelowColor.detects(blue)) {
            RightTouchLED.setColor(blue);
          }
          else {
            if (BelowColor.detects(white)) {
              RightTouchLED.setColor(white);
            }
            else {
              if (BelowColor.detects(yellow)) {
                RightTouchLED.setColor(yellow);
              }
              else {
                if (BelowColor.detects(orange)) {
                  RightTouchLED.setColor(orange);
                }
                else {
                  if (BelowColor.detects(purple)) {
                    RightTouchLED.setColor(purple);
                  }
                  else {
                    if (BelowColor.detects(red_violet)) {
                      RightTouchLED.setColor(red_violet);
                    }
                    else {
                      if (BelowColor.detects(violet)) {
                        RightTouchLED.setColor(violet);
                      }
                      else {
                        if (BelowColor.detects(blue_violet)) {
                          RightTouchLED.setColor(blue_violet);
                        }
                        else {
                          if (BelowColor.detects(blue_green)) {
                            RightTouchLED.setColor(blue_green);
                          }
                          else {
                            if (BelowColor.detects(yellow_green)) {
                              RightTouchLED.setColor(yellow_green);
                            }
                            else {
                              if (BelowColor.detects(yellow_orange)) {
                                RightTouchLED.setColor(yellow_orange);
                              }
                              else {
                                if (BelowColor.detects(red_orange)) {
                                  RightTouchLED.setColor(red_orange);
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  wait(20, msec);
  }
}

// "when I receive message1" hat block
void onevent_message1_0() {
  // this says to play the random loop on the right touch led
  while (true) {
    LeftTouchLED.setColor(red);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(red_violet);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(red_orange);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(orange);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(yellow_orange);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(white);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(yellow);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(yellow_green);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(green);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(blue_green);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(blue);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(blue_violet);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(violet);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
    LeftTouchLED.setColor(purple);
    wait(0.25, seconds);
    LeftTouchLED.setFade(slow);
  wait(20, msec);
  }
}


int main() {
  // Calibrate the Drivetrain Gyro
  calibrateDrivetrain();

task rc_auto_loop_task_Controller(rc_auto_loop_function_Controller);

  // register event handlers
  message2(onevent_message2_0);
  message1(onevent_message1_0);

  wait(15, msec);
  vex::task ws1(whenStarted2);
  vex::task ws2(whenStarted3);
  whenStarted1();
}

The links don’t seem to be working (don’t have permission), can you explain how it’s not working?

Sure. Can you understand the code?
Try this link. - Robot - Google Slides

Do you mean BelowColor or FrontColor or do you mean the touch LED: RightTouchLED?

The problem might be you only refer to the FrontColor Sensor once, but the BelowColor is refered 16 times in the code. You might’ve forgotten to add the FrontColor Sensor code in?

1 Like

The code says to show the detected color on to the right touchLED. It finds the color from the Below Color sensor. So I believe that either the color sensor isn’t working or the connection between the below color sensor and the right touchled isn’t working.

The front color isnt really supposed to have a role in the code.

Oh okay.

I’m pretty sure if my memory of using a code sensor serves me well, the sensor usually gives out an output of two colours like red-orange. There is a chance it’s giving out the two colours.

On the IQ brain you can check sensors. If you go onto the colour sensor one, you’ll see a live output of the colour it sees. Make sure that’s giving a predictable output, and change your code accordingly.

1 Like

Do you mean the device info?

How would I change my code? I just see that it indeed does show the wrong color and hue.

Try changing the code to match the output. So whatever the output is for each colour in the device info, set that as what the code is looking for.

1 Like

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