Skip to content

Commit

Permalink
disco
Browse files Browse the repository at this point in the history
  • Loading branch information
ProgrammingSR committed Apr 4, 2024
1 parent 45f7957 commit 965692f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/main/java/frc/robot/commands/DefaultLEDCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public void initialize() {
rgb[2] = 257;
}

if (m_climberSubsystem.getState() == Value.kReverse){
rgb[0] = 258;
rgb[1] = 258;
rgb[2] = 258;
}

if (m_intakeSubsystem.getArmPosition() == IntakeConstants.kIntakeAmpScoringAngle){
if (m_intakeSubsystem.ampReady()){
rgb[0] = 0;
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/frc/robot/subsystems/LEDSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package frc.robot.subsystems;

import java.util.Random;

import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
Expand All @@ -15,6 +17,8 @@ public class LEDSubsystem extends SubsystemBase {
private final AddressableLEDBuffer m_LEDBuffer = new AddressableLEDBuffer(LEDConstants.kLEDLength);
private int m_rainbowFirstPixelHue = 0;

private Random rand = new Random();

/** Creates a new {@link LEDSubsystem}. */
public LEDSubsystem() {
m_LED.setLength(LEDConstants.kLEDLength); // 29
Expand All @@ -38,7 +42,7 @@ public void setLED(int r, int g, int b) {

// If we get an invalid value just set it to a rainbow
if (r == 256 && g == 256 && b == 256) {
rainbow();
disco();
return;
}

Expand All @@ -47,6 +51,11 @@ else if (r == 257 && g == 257 && b == 257){
return;
}

else if (r == 258 && g == 258 && b == 258){
disco();
return;
}

for (var i = 0; i < LEDConstants.kLEDLength; i++) {
m_LEDBuffer.setRGB(i, r, g, b);
}
Expand Down Expand Up @@ -77,7 +86,7 @@ private void golden() {
for (var i = 0; i < m_LEDBuffer.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 = (m_rainbowFirstPixelHue + (i * 180 / m_LEDBuffer.getLength())) % 120 + 90;
final var hue = (m_rainbowFirstPixelHue + (i * 180 / m_LEDBuffer.getLength())) % 120;
// Set the value
m_LEDBuffer.setHSV(i, hue, 240, 180);
}
Expand All @@ -87,6 +96,25 @@ private void golden() {
m_rainbowFirstPixelHue %= 120;


m_LED.setData(m_LEDBuffer);
SmartDashboard.putString("led", m_LEDBuffer.getLED(1).toString());
}

private void disco() {
// For every pixel
for (var i = 0; i < m_LEDBuffer.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 = (m_rainbowFirstPixelHue + (i * 180 / m_LEDBuffer.getLength())) % 120;
// Set the value
m_LEDBuffer.setHSV(i, hue, rand.nextInt(50, 180), rand.nextInt(50, 180));
}
// Increase by to make the rainbow "move"
m_rainbowFirstPixelHue += rand.nextInt(1, 8);
// Check bounds
m_rainbowFirstPixelHue %= 120;


m_LED.setData(m_LEDBuffer);
SmartDashboard.putString("led", m_LEDBuffer.getLED(1).toString());
}
Expand Down

0 comments on commit 965692f

Please sign in to comment.