Skip to content

Commit

Permalink
Turn fade and blink time to doubles and rename fadeDuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Emma03L committed Feb 4, 2024
1 parent 58aa2f8 commit 6e56b04
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/main/java/frc/robot/leds/LedStrip.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

import java.util.function.DoubleSupplier;
import java.util.function.IntSupplier;

public class LedStrip extends SubsystemBase {
Expand All @@ -24,7 +23,7 @@ public class LedStrip extends SubsystemBase {
private Color fadeColor = primary;

private double blinkTime = 1;
private double fadeDuration = 1;
private double fadeTime = 1;
private int percentage = 100;

private final Timer timer = new Timer();
Expand Down Expand Up @@ -64,7 +63,7 @@ private void updateFade(Color initial, Color goal) {
Translation3d initialPoint = new Translation3d(initial.red, initial.green, initial.blue);
Translation3d goalPoint = new Translation3d(goal.red, goal.green, goal.blue);

double d = initialPoint.getDistance(goalPoint) / fadeDuration;
double d = initialPoint.getDistance(goalPoint) / fadeTime;
double t = d / (initialPoint.minus(goalPoint)).getNorm();

Translation3d solution = initialPoint.interpolate(goalPoint, t);
Expand Down Expand Up @@ -138,17 +137,17 @@ public void setBlinkTime(double time) {
this.blinkTime = time;
}

public double getFadeDuration() {
return fadeDuration;
public double getFadeTime() {
return fadeTime;
}

/**
* Sets the duration for the fade effect.
*
* @param duration Duration of the fade effect. [sec]
*/
public void setFadeDuration(double duration) {
this.fadeDuration = duration;
public void setFadeTime(double duration) {
this.fadeTime = duration;
}

public int getPercentage() {
Expand Down Expand Up @@ -209,10 +208,10 @@ public Command percentage() {
return percentage(() -> percentage);
}

public Command blink(DoubleSupplier blinkTime) {
public Command blink(double blinkTime) {
return this.run(
() -> {
setBlinkTime(blinkTime.getAsDouble());
setBlinkTime(blinkTime);
currentColor = currentColor == primary ?
secondary : primary;

Expand All @@ -223,20 +222,20 @@ public Command blink(DoubleSupplier blinkTime) {
}

public Command blink() {
return blink(() -> blinkTime);
return blink(blinkTime);
}

public Command fade(DoubleSupplier fadeDuration) {
public Command fade(double fadeTime) {
return this.run(
() -> {
setFadeDuration(fadeDuration.getAsDouble());
setFadeTime(fadeTime);
updateFade(primary, secondary);
setSolidColor(fadeColor);
});
}

public Command fade() {
return fade(() -> fadeDuration);
return fade(fadeTime);
}

public Command rainbow() {
Expand Down

0 comments on commit 6e56b04

Please sign in to comment.