Shuffleboard Color Block For Color Sensor

Team 3673 Cyborg Seagulls found a way to display on shuffleboard a color block, if the color sensor detects a color.

We have seen a couple questions about how to do this, and we wanted to show you guys how we have done it. To start off, we used basic Rev Robotics example color sensor code.

Color Sensor BLocks

We added four booleans for each of the colors and set them to false. We’ve set false as the default, until the color sensor detected the color. Which then set it to true in the if-else statements when the color was detected.

After that we added the last four lines of code to show the booleans on shuffleboard.

After uploading your code, open shuffleboard and change the properties of the booleans to the preferred color.


Hah, clever! This makes it easy to tell what color is use not just by the displayed color, but also where the widget is on the screen.

You can also do this purely from your robot code without needing to touch properties in the dashboard:

  .addBoolean("isRed", () -> match.color == kRedTarget)
  .withProperties(Map.of("colorWhenTrue", "red"));
  .addBoolean("isYellow", () -> match.color == kYellowTarget)
  .withProperties(Map.of("colorWhenTrue", "yellow"));
  .addBoolean("isBlue", () -> match.color == kBlueTarget)
  .withProperties(Map.of("colorWhenTrue", "blue"));
  .addBoolean("isGreen", () -> match.color == kGreenTarget)
  .withProperties(Map.of("colorWhenTrue", "green"));

(this sample code is of course a rough pass for demonstration; it’s not the prettiest and can be easily DRYed out)


Wonderful add to the code. I’ll try it out tomorrow

From what I’ve observed, you can change colorWhenTrue on the fly. Something like this works to change the color on a single widget:

private SuppliedValueWidget colorWidget = 
    Shuffleboard.getTab("MyBot").addBoolean("Color", () -> true);

public void periodic() {
  colorWidget.withProperties(Map.of("colorWhenTrue", match.color);
1 Like