I am starting to learn how to use addressable LEDs in wpilib’s java kit. The prototype bot that I’m currently testing on has 2 strips connected to the same PWM port, so in software they behave as one continuous strip. Is there a way to make it so one have of the strip is a different color than the other half? My idea is that when the robot is going forwards, the light turns green, and backwards shows red. That part works fine, but if I was turning, I wanted the LEDs to reflect that one side of the robot is going forwards, and the other is going reverse, so one side is green, one is red. I’ve looked at the docs already, and couldn’t find an answer there.
Are they connected so they look like the same device, or that one is appended to the other? E.g, if each has 30 LEDs, does addressing LED 15 affect two LEDs or one? If they look the same, you’re pretty much out of luck unless you can rewire them to look consecutive. If they’re appended then in one case you assign LEDs 0 through 29 red and LEDs 30 through 59 green; in the other case, swap colors.
If you need more help with this, knowing what model LED strip you’re using would be helpful! (and maybe a picture of your wiring!)
I don’t know most of those electrical terms (I’m a software guy) but it looks like one strip is connected to the other, and the other one is connected to the PWM, so in software it would be one continuous strip of 34 LEDs, just physically split in half
You have one strip of 34 LEDs, but you can effectively treat it as two different strips. The second one just has to have the offset to begin indexing at LED 17.
I’ve never used the WPILIB addressable LED driver myself, but after looking at the docs, it would be something like the following, in place of the snippet from the WPILIB page. Replace “throttle” with something which indicates whether you’re going forward or backward by whether it is positive or negative.
for (var i = 0; i < m_ledBuffer.getLength(); i++) {
// Sets the specified LED to the RGB values for red or green
if ((i<m_ledBuffer.getLength()/2) ^ (throttle >=0))
m_ledBuffer.setRGB(i, 255, 0, 0); //red
else
m_ledBuffer.setRGB(i, 0, 255, 0); //green
}
m_led.setData(m_ledBuffer);
OBTW, the ^ is the exclusive or operator. In the case of booleans, it’s actually the same as !=, so you could use that instead.
As @Mr.R_2 indicates below, the argument to the setData() is an array of what colors you want the LEDs to be. If your control loops get too tight (doubtful, but it might happen), you can make two versions of m_ledBuffer [e.g m_ledBufferForward and m_ledBufferReverse] and run the for loop in your constructor, then just have the final if in your periodic code.
If you want to mess with LEDs with a system very similar to WPILib’s, Adafruits’s NeoPixel/FastLED library is fantastic. They have an arduino library, and you can grab an arduino and a light strip, take it home, and create as many effects as you want. The “buffer” system is very similar between the two, so any effects you write can be transferred to the RIO later. There’s a full guide in that link and a LOT of resources to steal from if needed. It’s one of my personal favorite side projects (plus once you’re out of FRC you now have a way to light up your dorm )
Its slightly different then that. You declare the right number of LED’s, but only the first half of the buffer will be used, and every pixel will be doubled. But the fix will be in the new image that fixes SPI gyros too, which should be out soon.