Class RGBWColor

java.lang.Object
com.ctre.phoenix6.signals.RGBWColor

public class RGBWColor extends Object
Represents an RGBW color that can be applied to an LED.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    The blue component of the color, within [0, 255].
    final int
    The green component of the color, within [0, 255].
    final int
    The red component of the color, within [0, 255].
    final int
    The white component of the color, within [0, 255].
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new RGBW color where all components are off.
    RGBWColor(int red, int green, int blue)
    Creates a new RGB color from the given 8-bit components.
    RGBWColor(int red, int green, int blue, int white)
    Creates a new RGBW color from the given 8-bit components.
    Creates a new RGBW color from a WPILib color.
    Creates a new RGBW color from a WPILib 8-bit color.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(Object other)
     
    Creates a new RGBW color from the given hex string.
    static RGBWColor
    fromHSV(double h, double s, double v)
    Creates a new RGBW color from the given HSV color.
    static RGBWColor
    fromHSV(Angle h, double s, double v)
    Creates a new RGBW color from the given HSV color.
    int
     
    scaleBrightness(double brightness)
    Scales down the components of this color by the given brightness.
    Returns this RGBW color as a hex string.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • Red

      public final int Red
      The red component of the color, within [0, 255].
    • Green

      public final int Green
      The green component of the color, within [0, 255].
    • Blue

      public final int Blue
      The blue component of the color, within [0, 255].
    • White

      public final int White
      The white component of the color, within [0, 255]. Note that not all LED strips support the white component.
  • Constructor Details

    • RGBWColor

      public RGBWColor()
      Creates a new RGBW color where all components are off.
    • RGBWColor

      public RGBWColor(int red, int green, int blue)
      Creates a new RGB color from the given 8-bit components.
      Parameters:
      red - The red component of the color, within [0, 255].
      green - The green component of the color, within [0, 255].
      blue - The blue component of the color, within [0, 255].
    • RGBWColor

      public RGBWColor(int red, int green, int blue, int white)
      Creates a new RGBW color from the given 8-bit components.
      Parameters:
      red - The red component of the color, within [0, 255].
      green - The green component of the color, within [0, 255].
      blue - The blue component of the color, within [0, 255].
      white - The white component of the color, within [0, 255]. Note that not all LED strips support the white component.
    • RGBWColor

      public RGBWColor(Color color)
      Creates a new RGBW color from a WPILib color. The white component will be left 0.
      Parameters:
      color - The WPILib color
    • RGBWColor

      public RGBWColor(Color8Bit color)
      Creates a new RGBW color from a WPILib 8-bit color. The white component will be left 0.
      Parameters:
      color - The WPILib color
  • Method Details

    • fromHex

      public static Optional<RGBWColor> fromHex(String hex)
      Creates a new RGBW color from the given hex string.
      Parameters:
      hex - The color hex in the form "#RRGGBBWW" or "#RRGGBB".
      Returns:
      The color if the hex is valid, otherwise Optional.empty()
    • fromHSV

      public static RGBWColor fromHSV(double h, double s, double v)
      Creates a new RGBW color from the given HSV color.
      Parameters:
      h - The hue as an angle from [0, 360) deg, where 0 is red.
      s - The saturation as a scalar from [0, 1].
      v - The value as a scalar from [0, 1].
      Returns:
      The corresponding RGB color; the white component will be 0.
    • fromHSV

      public static RGBWColor fromHSV(Angle h, double s, double v)
      Creates a new RGBW color from the given HSV color.
      Parameters:
      h - The hue as an angle from [0, 360) deg.
      s - The saturation as a scalar from [0, 1].
      v - The value as a scalar from [0, 1].
      Returns:
      The corresponding RGB color; the white component will be 0.
    • scaleBrightness

      public RGBWColor scaleBrightness(double brightness)
      Scales down the components of this color by the given brightness.

      This function returns a new object every call. As a result, we recommend that this is not called inside a tight loop.

      Parameters:
      brightness - The scalar to apply from [0, 1].
      Returns:
      New color scaled by the given brightness
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toHexString

      public String toHexString()
      Returns this RGBW color as a hex string.
      Returns:
      A hex string in the format "#RRGGBBWW"