Skip to content

Commit

Permalink
Added loading animation
Browse files Browse the repository at this point in the history
  • Loading branch information
programming353 committed Jan 24, 2024
1 parent 80d7cf1 commit 530fb62
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@ public static final class ClimberConstants {

public static final class LEDConstants {
public static final int ledPort = 0;
public static final int bufferLength = 50;
public static final int bufferLength = 100;

public static final Color transparent = new Color(0, 0, 0);
public static final Color rslColor = new Color(255, 125, 25);
public static final Color rslColor = new Color(255, 25, 0);
}

public static final class SwerveConstants {
Expand Down
80 changes: 80 additions & 0 deletions src/main/java/frc/robot/commands/leds/LoadingAnimation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.commands.leds;

import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.Constants.LEDConstants;
import frc.robot.subsystems.LEDs;

public class LoadingAnimation extends Command {
private final LEDs leds;
private final Color color;

private static final int length = 12;
private static final int incrementAmount = 2;
private boolean increasing = true;
private int startOffset = 0;

/** Creates a new LoadingAnimation. */
public LoadingAnimation(Color color, LEDs leds) {
this.color = color;
this.leds = leds;

// Use addRequirements() here to declare subsystem dependencies.
addRequirements(leds);
}

@Override
public boolean runsWhenDisabled() {
return true;
}

// Called when the command is initially scheduled.
@Override
public void initialize() {
increasing = true;
startOffset = 0;
}

// Called every time the scheduler runs while the command is scheduled.
@Override
public void execute() {
AddressableLEDBuffer buffer = leds.getBuffer();
if (increasing) {
startOffset += incrementAmount;
} else {
startOffset -= incrementAmount;
}

if (increasing && startOffset + length >= buffer.getLength()) {
startOffset = buffer.getLength() - length;
increasing = false;
} else if (!increasing && startOffset <= 0) {
startOffset = 0;
increasing = true;
}

for (int i = 0; i < buffer.getLength(); i++) {
if (i >= startOffset && i <= startOffset + length) {
buffer.setLED(i, color);
} else {
buffer.setLED(i, LEDConstants.transparent);
}
}
leds.updateBuffer();
}

// Called once the command ends or is interrupted.
@Override
public void end(boolean interrupted) {}

// Returns true when the command should end.
@Override
public boolean isFinished() {
return false;
}
}
4 changes: 3 additions & 1 deletion src/main/java/frc/robot/commands/leds/RSLSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public boolean runsWhenDisabled() {

// Called when the command is initially scheduled.
@Override
public void initialize() {}
public void initialize() {
ledsOn = false;
}

// Called every time the scheduler runs while the command is scheduled.
@Override
Expand Down

0 comments on commit 530fb62

Please sign in to comment.