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. https://github.com/REVrobotics/Color-Sensor-v3-Examples

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.

5 Likes

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:

Shuffleboard.getTab("Colors")
  .addBoolean("isRed", () -> match.color == kRedTarget)
  .withProperties(Map.of("colorWhenTrue", "red"));
Shuffleboard.getTab("Colors")
  .addBoolean("isYellow", () -> match.color == kYellowTarget)
  .withProperties(Map.of("colorWhenTrue", "yellow"));
Shuffleboard.getTab("Colors")
  .addBoolean("isBlue", () -> match.color == kBlueTarget)
  .withProperties(Map.of("colorWhenTrue", "blue"));
Shuffleboard.getTab("Colors")
  .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)

5 Likes

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