Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPIKE: Addressable LEDs #14

Open
falOn-Dev opened this issue Jan 17, 2025 · 1 comment
Open

SPIKE: Addressable LEDs #14

falOn-Dev opened this issue Jan 17, 2025 · 1 comment
Labels
spike Research the topic, possibly do some testing

Comments

@falOn-Dev
Copy link
Contributor

falOn-Dev commented Jan 17, 2025

Using LED strips is a really good way to provide driver feedback, we need to figure out how to use them for this season. Do some research into WPILib's addressable LED features, as well as determining what our LED inventory looks like

Resources

Criteria

  • Comment on this issue with a list of what LEDs we have.
  • Read through the resources, and get an understanding of the API we're working with, write down your findings below (code snippets to do things like set colors, or do patterns, in Kotlin)
@falOn-Dev falOn-Dev added the spike Research the topic, possibly do some testing label Jan 17, 2025
@njchim njchim changed the title SPIKE: Adressable LEDs SPIKE: Addressable LEDs Jan 18, 2025
@JosieWedeking
Copy link

JosieWedeking commented Jan 18, 2025

static LEDPattern rainbow (int saturation, int value)

The saturation is the intensity of the color. For example, dark blue versus light blue. The value is the color itself. 0 is black, while 255 is white. Both saturation and intensity go from a value of 0 to 255.


A gradient is set up like this:

static LEDPattern gradient (LEDPattern.GradientType type, Colors...Colors.

The type refers to the "type of gradient": either discontinuous or continuous. Colors refer to the colors you'll display within the gradient. They can be written in either a HEX pattern or RGB values. The Google Color Picker can give you both HEX and RGB values. (Look up color picker on Google).


A solid color block is set up like this:

static LEDPattern solid (Color color)

The color (keep the uppercase, only change the lowercase) refers to the color you want. There are different codes you can place in for each color. For example, Color kCyan would automatically place a cyan color on the LED strip. For more codes, refer to this link: https://github.wpilib.org/allwpilib/docs/release/java/edu/wpi/first/wpilibj/util/Color.html


  • Step 2: translate the pattern to machine-readable data

    In order to make the pattern readable for the hardware itself, we need to implement a buffer. A buffer translates the code from what you write to something readable for the LED strip. You first need to create a variable at the beginning to establish the buffer:

private final AdressableLEDBuffer m_ledBuffer


The buffer then needs to get the length of the LED strip measured by the amount of LEDs on the strip. This will allow for the pattern to be displayed on the LED strip with the right proportions.

m_ledBuffer = new AddressableLEDBuffer(60);
m_led.setLength(m_ledBuffer.getLength());

60 refers to the length of the LED strip. Setters and getters are also used.


The data is then set to the buffer so it can be translated into readable code.

m_led.setData(m_ledBuffer);
m_led.start();


  • Step 3: send machine-readable data to the physical LED strip.

The LED pattern is set to buffer within a periodic function (every 20 milliseconds, the code will look at where the colors are and adjust to continue with the pattern.

public void robotPeriodic() {
m_scrollingRainbow.applyTo(m_ledBuffer);
m_led.setData(m_ledBuffer);

"m_scrollingRainbow" can be substituted with any type of color animation. Refer to Step 1 for three of the coolest (and simplest to explain) patterns you can use.

There are other variables and steps required, but this comment should clear up the main requirements specific to LED strips themselves. Refer to the link at the introduction to look at example code.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spike Research the topic, possibly do some testing
Projects
None yet
Development

No branches or pull requests

2 participants