From 3a45f902a2728fb269bb3debd132da97d0d42248 Mon Sep 17 00:00:00 2001 From: programming353 <58999047+programming353@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:27:21 -0500 Subject: [PATCH 1/2] Lights --- .../robot/commands/leds/FlashingLights.java | 63 +++++++++++++++++++ .../frc/robot/commands/leds/IntakeLight.java | 62 ++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 src/main/java/frc/robot/commands/leds/FlashingLights.java create mode 100644 src/main/java/frc/robot/commands/leds/IntakeLight.java diff --git a/src/main/java/frc/robot/commands/leds/FlashingLights.java b/src/main/java/frc/robot/commands/leds/FlashingLights.java new file mode 100644 index 0000000..5fee87f --- /dev/null +++ b/src/main/java/frc/robot/commands/leds/FlashingLights.java @@ -0,0 +1,63 @@ +// 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; +import edu.wpi.first.wpilibj.Timer; + +public class FlashingLights extends Command { + private final Color color; + private final LEDs leds; + private Timer timer = new Timer(); + double time; + + /** Creates a new FlashingLights. */ + public FlashingLights(double time,Color color, LEDs leds) { + this.color = color; + this.leds = leds; + + // Use addRequirements() here to declare subsystem dependencies. + addRequirements(leds); + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + double getTime = timer.get(); + AddressableLEDBuffer buffer = leds.getBuffer(); + if (getTime <= time) { + for (int i = 0; i < buffer.getLength(); i++) { + buffer.setLED(i, color); + } + leds.updateBuffer(); + } else if(getTime >= 2*time) { + timer.restart(); + } else { + for (int i = 0; i < buffer.getLength(); i++){ + buffer.setLED(i, LEDConstants.transparent); + } + } + } + + // 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; + } +} diff --git a/src/main/java/frc/robot/commands/leds/IntakeLight.java b/src/main/java/frc/robot/commands/leds/IntakeLight.java new file mode 100644 index 0000000..befb783 --- /dev/null +++ b/src/main/java/frc/robot/commands/leds/IntakeLight.java @@ -0,0 +1,62 @@ +// 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.Intake; +import frc.robot.subsystems.LEDs; + +public class IntakeLight extends Command { + /** Creates a new IntakeLight. */ + private final Color color; + private final LEDs leds; + private final Intake intake; + + public IntakeLight(Intake intake,Color color, LEDs leds) { + this.color = color; + this.leds = leds; + this.intake = intake; + + addRequirements(leds); + addRequirements(intake); + } + + // Use addRequirements() here to declare subsystem dependencies. + + + // Called when the command is initially scheduled. + @Override + public void initialize() {} + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() { + + AddressableLEDBuffer buffer = leds.getBuffer(); + + if(intake.isIRBeamBreakBroken()) { + for (int i = 0; i < buffer.getLength(); i++) { + buffer.setLED(i, color); + } + } else { + for (int i = 0; i < buffer.getLength(); i++) { + buffer.setLED(i, LEDConstants.transparent); + } + + } + } + // 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; + } +} From c567ff901f9013b4d71949c0aab76e5489c05dff Mon Sep 17 00:00:00 2001 From: programming353 <58999047+programming353@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:48:12 -0500 Subject: [PATCH 2/2] Fixed lights --- .../robot/commands/leds/FlashingLights.java | 35 ++++++----- .../frc/robot/commands/leds/IntakeLight.java | 62 ------------------- 2 files changed, 21 insertions(+), 76 deletions(-) delete mode 100644 src/main/java/frc/robot/commands/leds/IntakeLight.java diff --git a/src/main/java/frc/robot/commands/leds/FlashingLights.java b/src/main/java/frc/robot/commands/leds/FlashingLights.java index 5fee87f..9e753ea 100644 --- a/src/main/java/frc/robot/commands/leds/FlashingLights.java +++ b/src/main/java/frc/robot/commands/leds/FlashingLights.java @@ -5,20 +5,22 @@ package frc.robot.commands.leds; import edu.wpi.first.wpilibj.AddressableLEDBuffer; +import edu.wpi.first.wpilibj.Timer; import edu.wpi.first.wpilibj.util.Color; import edu.wpi.first.wpilibj2.command.Command; import frc.robot.Constants.LEDConstants; import frc.robot.subsystems.LEDs; -import edu.wpi.first.wpilibj.Timer; public class FlashingLights extends Command { private final Color color; private final LEDs leds; private Timer timer = new Timer(); - double time; + + private double period; + private boolean ledsOn = false; /** Creates a new FlashingLights. */ - public FlashingLights(double time,Color color, LEDs leds) { + public FlashingLights(double period, Color color, LEDs leds) { this.color = color; this.leds = leds; @@ -29,30 +31,35 @@ public FlashingLights(double time,Color color, LEDs leds) { // Called when the command is initially scheduled. @Override public void initialize() { + timer.start(); + ledsOn = false; } // Called every time the scheduler runs while the command is scheduled. @Override public void execute() { - double getTime = timer.get(); - AddressableLEDBuffer buffer = leds.getBuffer(); - if (getTime <= time) { - for (int i = 0; i < buffer.getLength(); i++) { - buffer.setLED(i, color); + if (timer.advanceIfElapsed(period)) { + AddressableLEDBuffer buffer = leds.getBuffer(); + ledsOn = !ledsOn; + if (ledsOn) { + for (int i = 0; i < buffer.getLength(); i++) { + buffer.setLED(i, color); + } + } else { + for (int i = 0; i < buffer.getLength(); i++) { + buffer.setLED(i, LEDConstants.transparent); + } } + leds.updateBuffer(); - } else if(getTime >= 2*time) { - timer.restart(); - } else { - for (int i = 0; i < buffer.getLength(); i++){ - buffer.setLED(i, LEDConstants.transparent); - } } } // Called once the command ends or is interrupted. @Override public void end(boolean interrupted) { + timer.stop(); + timer.reset(); } // Returns true when the command should end. diff --git a/src/main/java/frc/robot/commands/leds/IntakeLight.java b/src/main/java/frc/robot/commands/leds/IntakeLight.java deleted file mode 100644 index befb783..0000000 --- a/src/main/java/frc/robot/commands/leds/IntakeLight.java +++ /dev/null @@ -1,62 +0,0 @@ -// 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.Intake; -import frc.robot.subsystems.LEDs; - -public class IntakeLight extends Command { - /** Creates a new IntakeLight. */ - private final Color color; - private final LEDs leds; - private final Intake intake; - - public IntakeLight(Intake intake,Color color, LEDs leds) { - this.color = color; - this.leds = leds; - this.intake = intake; - - addRequirements(leds); - addRequirements(intake); - } - - // Use addRequirements() here to declare subsystem dependencies. - - - // Called when the command is initially scheduled. - @Override - public void initialize() {} - - // Called every time the scheduler runs while the command is scheduled. - @Override - public void execute() { - - AddressableLEDBuffer buffer = leds.getBuffer(); - - if(intake.isIRBeamBreakBroken()) { - for (int i = 0; i < buffer.getLength(); i++) { - buffer.setLED(i, color); - } - } else { - for (int i = 0; i < buffer.getLength(); i++) { - buffer.setLED(i, LEDConstants.transparent); - } - - } - } - // 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; - } -}