Addressable RGB patterns

I’ve recently gotten LEDs working on our robot but I’m having some trouble with getting patterns to work. The patterns our team would like to use are a rainbow wave and a uniform color that blinks.

s1xGT

For the blinking lights, could this just be done by adding a timer to setting the color, something like this?

@Override
public void periodic() {
    timer.start();
    if (timer.get() < 0.5) {
        setYellow();
    }
    timer.start();
    if (timer.get() < 0.5) {
        setOff();
    }
}

I’m not sure how to do the rainbow chasing effect though.

This is what I have for setting the LEDs to be rainbow without a wave:

public void setRainbow() {
        for (var i = 0; i < m_Buffer.getLength(); i++) {
            final var hue = (m_RainbowFirstPixelHue + (i * 180 / m_Buffer.getLength())) % 180;
            m_Buffer.setHSV(i, hue, 255, 128);
        }
        m_RainbowFirstPixelHue += 3;
        m_RainbowFirstPixelHue %= 180;
}

but I’m not sure how to make them do the wave. Does anyone know how I can do this? Thanks!!

Here are all of our LEDs commands/patterns, FRC2023/src/main/java/frc/robot/commands/leds at main · Frc5572/FRC2023 · GitHub. Remember that the periodic function gets called every 20ms so a lot of times u don’t need a timer urself, just keep track of how many times the function is called and then do something else. For blinking the strip a single color, I let it run 10 loops (200ms) and then change the color for another 10 loops and repeat. This makes it blink.

1 Like

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