Skip to content

Commit

Permalink
new led system
Browse files Browse the repository at this point in the history
will be removed in the next update as i don't like redoing what the command scheduler already did. so will create a singleton LEDSubsystem and get the subsystem trough the LEDSystem.java by doing `LEDSystem.getInstance()`
  • Loading branch information
kytpbs committed Mar 28, 2024
1 parent a9a3dcb commit daf04fb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/main/java/frc/robot/subsystems/LEDSubsystem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package frc.robot.subsystems;

import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants.LEDConstants;
import frc.utils.BetterLED;

public class LEDSubsystem extends SubsystemBase {
BetterLED strip;

public LEDSubsystem() {
strip = new BetterLED(LEDConstants.kLedPin, LEDConstants.kLedCount);
}

public BetterLED getStrip() {
return strip;
}
}
37 changes: 35 additions & 2 deletions src/main/java/frc/robot/subsystems/LEDSystem.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
package frc.robot.subsystems;

import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.util.Color;
import frc.robot.Constants.LEDConstants;
import frc.utils.BetterLED;
import java.util.function.BooleanSupplier;

public final class LEDSystem {
private static final BetterLED strip =
new BetterLED(LEDConstants.kLedPin, LEDConstants.kLedCount);
private static boolean isRunningACommand = false;

public static void init() {
System.out.println("Startup LED System!");
}

public static void setLEDColorRGB(int r, int g, int b) {
strip.fill(new Color(r, g, b));
}

public static void init() {
System.out.println("Startup LED System!");
public static boolean isRunningACommand() {
return isRunningACommand;
}

public static void setRunningACommand(boolean isRunningACommand) {
LEDSystem.isRunningACommand = isRunningACommand;
}

public static void addTimedCommand(double timeSeconds) {
isRunningACommand = true;
new Thread(
() -> {
Timer.delay(timeSeconds);
isRunningACommand = false;
})
.start();
}

public static void addBooleanSupplierCommand(BooleanSupplier hasEnded) {
isRunningACommand = true;
new Thread(
() -> {
while (!hasEnded.getAsBoolean()) {
Timer.delay(0.1);
}
isRunningACommand = false;
})
.start();
}
}

0 comments on commit daf04fb

Please sign in to comment.