-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAddressableLEDSubsystem.java
More file actions
47 lines (40 loc) · 1.58 KB
/
AddressableLEDSubsystem.java
File metadata and controls
47 lines (40 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package frc.robot.subsystems.addressableled;
import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj.AddressableLEDBufferView;
import edu.wpi.first.wpilibj.LEDPattern;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
public class AddressableLEDSubsystem extends SubsystemBase {
private final AddressableLED led;
private final AddressableLEDBuffer ledBuffer;
private AddressableLEDBufferView ledViews[];
public AddressableLEDSubsystem() {
// Create strip and buffer
led = new AddressableLED(AddressableLEDConstants.LED_STRIP_PORT);
ledBuffer = new AddressableLEDBuffer(AddressableLEDConstants.LED_COUNT);
led.setLength(AddressableLEDConstants.LED_COUNT);
// Create section views
ledViews = new AddressableLEDBufferView[AddressableLEDConstants.SECTIONS.length];
for (int i = 0; i < ledViews.length; i++) {
ledViews[i] =
new AddressableLEDBufferView(
ledBuffer,
AddressableLEDConstants.SECTIONS[i].low(),
AddressableLEDConstants.SECTIONS[i].high());
}
}
// Periodically update the LED strip
@Override
public void periodic() {
led.setData(ledBuffer);
}
// Apply a color pattern to a section of the LED strip
public void applySectionedPattern(LEDPattern pattern, int section) {
if (section < 0 || section >= ledViews.length) return;
pattern.applyTo(ledViews[section]);
}
// Apply a color pattern to a section of the LED strip
public void applyPattern(LEDPattern pattern) {
pattern.applyTo(ledBuffer);
}
}