|
| LEDPattern (std::function< void(frc::LEDPattern::LEDReader, std::function< void(int, frc::Color)>)> impl) |
|
void | ApplyTo (LEDReader reader, std::function< void(int, frc::Color)> writer) const |
|
void | ApplyTo (std::span< frc::AddressableLED::LEDData > data, std::function< void(int, frc::Color)> writer) const |
| Writes the pattern to an LED buffer.
|
|
void | ApplyTo (std::span< frc::AddressableLED::LEDData > data) const |
| Writes the pattern to an LED buffer.
|
|
LEDPattern | MapIndex (std::function< size_t(size_t, size_t)> indexMapper) |
| Creates a pattern with remapped indices.
|
|
LEDPattern | Reversed () |
| Creates a pattern that displays this one in reverse.
|
|
LEDPattern | OffsetBy (int offset) |
| Creates a pattern that displays this one, but offset by a certain number of LEDs.
|
|
LEDPattern | ScrollAtRelativeSpeed (units::hertz_t velocity) |
| Creates a pattern that plays this one scrolling up the buffer.
|
|
LEDPattern | ScrollAtAbsoluteSpeed (units::meters_per_second_t velocity, units::meter_t ledSpacing) |
| Creates a pattern that plays this one scrolling up an LED strip.
|
|
LEDPattern | Blink (units::second_t onTime, units::second_t offTime) |
| Creates a pattern that switches between playing this pattern and turning the entire LED strip off.
|
|
LEDPattern | Blink (units::second_t onTime) |
| Like LEDPattern::Blink(units::second_t) , but where the "off" time is exactly equal to the "on" time.
|
|
LEDPattern | SynchronizedBlink (std::function< bool()> signal) |
| Creates a pattern that blinks this one on and off in sync with a true/false signal.
|
|
LEDPattern | Breathe (units::second_t period) |
| Creates a pattern that brightens and dims this one over time.
|
|
LEDPattern | OverlayOn (const LEDPattern &base) |
| Creates a pattern that plays this pattern overlaid on another.
|
|
LEDPattern | Blend (const LEDPattern &other) |
| Creates a pattern that displays outputs as a combination of this pattern and another.
|
|
LEDPattern | Mask (const LEDPattern &mask) |
| Similar to LEDPattern::Blend(const LEDPattern&) , but performs a bitwise mask on each color channel rather than averaging the colors for each LED.
|
|
LEDPattern | AtBrightness (double relativeBrightness) |
| Creates a pattern that plays this one, but at a different brightness.
|
|
|
static LEDPattern | Off () |
| A pattern that turns off all LEDs.
|
|
static LEDPattern | Solid (const Color color) |
| Creates a pattern that displays a single static color along the entire length of the LED strip.
|
|
static LEDPattern | ProgressMaskLayer (std::function< double()> progressFunction) |
| Creates a pattern that works as a mask layer for LEDPattern::Mask(const LEDPattern&) that illuminates only the portion of the LED strip corresponding with some progress.
|
|
static LEDPattern | Steps (std::span< const std::pair< double, Color > > steps) |
| Display a set of colors in steps across the length of the LED strip.
|
|
static LEDPattern | Steps (std::initializer_list< std::pair< double, Color > > steps) |
| Display a set of colors in steps across the length of the LED strip.
|
|
static LEDPattern | Gradient (GradientType type, std::span< const Color > colors) |
| Creates a pattern that displays a non-animated gradient of colors across the entire length of the LED strip.
|
|
static LEDPattern | Gradient (GradientType type, std::initializer_list< Color > colors) |
| Creates a pattern that displays a non-animated gradient of colors across the entire length of the LED strip.
|
|
static LEDPattern | Rainbow (int saturation, int value) |
| Creates an LED pattern that displays a rainbow across the color wheel.
|
|
Writes the pattern to an LED buffer.
Dynamic animations should be called periodically (such as with a command or with a periodic method) to refresh the buffer over time.
This method is intentionally designed to use separate objects for reading and writing data. By splitting them up, we can easily modify the behavior of some base pattern to make it scroll, blink, or breathe by intercepting the data writes to transform their behavior to whatever we like.
- Parameters
-
data | the current data of the LED strip |
Writes the pattern to an LED buffer.
Dynamic animations should be called periodically (such as with a command or with a periodic method) to refresh the buffer over time.
This method is intentionally designed to use separate objects for reading and writing data. By splitting them up, we can easily modify the behavior of some base pattern to make it scroll, blink, or breathe by intercepting the data writes to transform their behavior to whatever we like.
- Parameters
-
data | the current data of the LED strip |
writer | data writer for setting new LED colors on the LED strip |
LEDPattern frc::LEDPattern::AtBrightness |
( |
double | relativeBrightness | ) |
|
|
nodiscard |
Creates a pattern that plays this one, but at a different brightness.
Brightness multipliers are applied per-channel in the RGB space; no HSL or HSV conversions are applied. Multipliers are also uncapped, which may result in the original colors washing out and appearing less saturated or even just a bright white.
This method is predominantly intended for dimming LEDs to avoid painfully bright or distracting patterns from playing (apologies to the 2024 NE Greater Boston field staff).
For example, dimming can be done simply by adding a call to atBrightness
at the end of a pattern:
// Solid red, but at 50% brightness
frc::LEDPattern::Solid(frc::Color::kRed).AtBrightness(0.5);
// Solid white, but at only 10% (i.e. ~0.5V)
frc::LEDPattern::Solid(frc:Color::kWhite).AtBrightness(0.1);
- Parameters
-
relativeBrightness | the multiplier to apply to all channels to modify brightness |
- Returns
- the input pattern, displayed at
Creates a pattern that displays a non-animated gradient of colors across the entire length of the LED strip.
Colors are evenly distributed along the full length of the LED strip. The gradient type is configured with the type
parameter, allowing the gradient to be either continuous (no seams, good for scrolling effects) or discontinuous (a clear seam is visible, but the gradient applies to the full length of the LED strip without needing to use some space for wrapping).
- Parameters
-
type | the type of gradient (continuous or discontinuous) |
colors | the colors to display in the gradient |
- Returns
- a motionless gradient pattern
Creates a pattern that displays a non-animated gradient of colors across the entire length of the LED strip.
Colors are evenly distributed along the full length of the LED strip. The gradient type is configured with the type
parameter, allowing the gradient to be either continuous (no seams, good for scrolling effects) or discontinuous (a clear seam is visible, but the gradient applies to the full length of the LED strip without needing to use some space for wrapping).
- Parameters
-
type | the type of gradient (continuous or discontinuous) |
colors | the colors to display in the gradient |
- Returns
- a motionless gradient pattern
Similar to LEDPattern::Blend(const LEDPattern&)
, but performs a bitwise mask on each color channel rather than averaging the colors for each LED.
This can be helpful for displaying only a portion of the base pattern by applying a mask that sets the desired area to white, and all other areas to black. However, it can also be used to display only certain color channels or hues; for example, masking with
LEDPattern.color(Color.kRed)
will turn off the green and blue channels on the output pattern, leaving only the red LEDs to be illuminated.
- Parameters
-
- Returns
- the masked pattern
static LEDPattern frc::LEDPattern::ProgressMaskLayer |
( |
std::function< double()> | progressFunction | ) |
|
|
static |
Creates a pattern that works as a mask layer for LEDPattern::Mask(const LEDPattern&)
that illuminates only the portion of the LED strip corresponding with some progress.
The mask pattern will start from the base and set LEDs to white at a proportion equal to the progress returned by the function. Some usages for this could be for displaying progress of a flywheel to its target velocity, progress of a complex autonomous sequence, or the height of an elevator.
For example, creating a mask for displaying a red-to-blue gradient, starting from the red end, based on where an elevator is in its range of travel.
frc::LEDPattern basePattern =
frc::LEDPattern::Gradient(frc::Color::kRed, frc::Color::kBlue);
frc::LEDPattern progressPattern =
basePattern.Mask(frc::LEDPattern::ProgressMaskLayer([&]() {
return elevator.GetHeight() / elevator.MaxHeight();
});
- Parameters
-
progressFunction | the function to call to determine the progress. This should return values in the range [0, 1]; any values outside that range will be clamped. |
- Returns
- the mask pattern
LEDPattern frc::LEDPattern::ScrollAtAbsoluteSpeed |
( |
units::meters_per_second_t | velocity, |
|
|
units::meter_t | ledSpacing ) |
|
nodiscard |
Creates a pattern that plays this one scrolling up an LED strip.
A negative velocity makes the pattern play in reverse.
For example, scrolling a pattern at 4 inches per second along an LED strip with 60 LEDs per meter:
// LEDs per meter, a known value taken from the spec sheet of our
particular LED strip units::meter_t LED_SPACING = units::meter_t{1 /60.0};
frc::LEDPattern rainbow = frc::LEDPattern::Rainbow();
frc::LEDPattern scrollingRainbow =
rainbow.ScrollAtAbsoluteSpeed(units::feet_per_second_t{1 / 3.0},
LED_SPACING);
Note that this pattern will scroll faster if applied to a less dense LED strip (such as 30 LEDs per meter), or slower if applied to a denser LED strip (such as 120 or 144 LEDs per meter).
- Parameters
-
velocity | how fast the pattern should move along a physical LED strip |
ledSpacing | the distance between adjacent LEDs on the physical LED strip |
- Returns
- the scrolling pattern