forked from JayK445/advantage-kit-migrate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
defe223
commit cdacfb5
Showing
6 changed files
with
64 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package frc.robot.subsystems; | ||
|
||
import edu.wpi.first.wpilibj.AddressableLED; | ||
import edu.wpi.first.wpilibj.AddressableLEDBuffer; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
public class LightsSubsystem extends SubsystemBase{ | ||
private final AddressableLED lights; | ||
private final AddressableLEDBuffer buffer; | ||
private int firstPixelHue; | ||
public LightsSubsystem() { | ||
lights = new AddressableLED(34); | ||
// turn off the LEDs when the can chain fails | ||
buffer = new AddressableLEDBuffer(227); | ||
lights.setLength(buffer.getLength()); | ||
lights.setData(buffer); | ||
lights.start(); | ||
firstPixelHue = 0; | ||
} | ||
private void rainbow() { | ||
// For every pixel | ||
for (var i = 0; i < buffer.getLength(); i++) { | ||
// Calculate the hue - hue is easier for rainbows because the color | ||
// shape is a circle so only one value needs to precess | ||
final var hue = (firstPixelHue + (i * 180 / buffer.getLength())) % 180; | ||
// Set the value | ||
buffer.setHSV(i, hue, 255, 128); | ||
} | ||
// Increase by to make the rainbow "move" | ||
firstPixelHue += 3; | ||
// Check bounds | ||
firstPixelHue %= 180; | ||
} | ||
|
||
@Override | ||
public void periodic(){ | ||
rainbow(); | ||
lights.setData(buffer); | ||
} | ||
} |
Oops, something went wrong.