From eb141ac2bad04f1635da50b44cb4ed22ded7e80f Mon Sep 17 00:00:00 2001 From: Antoine PerreaultE Date: Mon, 17 Feb 2025 18:45:04 -0500 Subject: [PATCH] leds --- src/main/java/frc/robot/RobotContainer.java | 4 +- .../java/frc/robot/commands/GrimperHaut.java | 13 +++++- src/main/java/frc/robot/commands/RainBow.java | 41 +++++++++++++++++++ .../java/frc/robot/subsystems/Bougie.java | 38 +++++++++++++++++ 4 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 src/main/java/frc/robot/commands/RainBow.java create mode 100644 src/main/java/frc/robot/subsystems/Bougie.java diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 5e95786..a990732 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -9,18 +9,20 @@ import edu.wpi.first.wpilibj2.command.Commands; import edu.wpi.first.wpilibj2.command.button.CommandXboxController; import frc.robot.commands.GrimperHaut; import frc.robot.commands.GrimpeurBas; +import frc.robot.subsystems.Bougie; import frc.robot.subsystems.Grimpeur; public class RobotContainer { CommandXboxController manette1 = new CommandXboxController(0); CommandXboxController manette2 = new CommandXboxController(1); Grimpeur grimpeur = new Grimpeur(); + Bougie bougie = new Bougie(); public RobotContainer() { configureBindings(); } private void configureBindings() { - manette1.leftBumper().whileTrue(new GrimperHaut(grimpeur)); + manette1.leftBumper().whileTrue(new GrimperHaut(grimpeur,bougie)); manette1.rightBumper().whileTrue(new GrimpeurBas(grimpeur)); } diff --git a/src/main/java/frc/robot/commands/GrimperHaut.java b/src/main/java/frc/robot/commands/GrimperHaut.java index 29abdf8..ad0ebf0 100644 --- a/src/main/java/frc/robot/commands/GrimperHaut.java +++ b/src/main/java/frc/robot/commands/GrimperHaut.java @@ -5,15 +5,18 @@ package frc.robot.commands; import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.subsystems.Bougie; import frc.robot.subsystems.Grimpeur; /* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */ public class GrimperHaut extends Command { private Grimpeur grimpeur; + private Bougie bougie; /** Creates a new Grimper. */ - public GrimperHaut(Grimpeur grimpeur) { + public GrimperHaut(Grimpeur grimpeur, Bougie bougie) { this.grimpeur = grimpeur; - addRequirements(grimpeur); + this.bougie = bougie; + addRequirements(grimpeur,bougie); // Use addRequirements() here to declare subsystem dependencies. } @@ -27,9 +30,11 @@ public class GrimperHaut extends Command { if(grimpeur.stop()==true){ grimpeur.grimpe(0); grimpeur.reset(); + bougie.RainBow(); } else{ grimpeur.grimpe(0.5); + bougie.RainBowStop(); } } @@ -37,6 +42,10 @@ public class GrimperHaut extends Command { @Override public void end(boolean interrupted) { grimpeur.grimpe(0); + if(grimpeur.stop()){ + bougie.RainBow(); + } + } // Returns true when the command should end. diff --git a/src/main/java/frc/robot/commands/RainBow.java b/src/main/java/frc/robot/commands/RainBow.java new file mode 100644 index 0000000..37f2d68 --- /dev/null +++ b/src/main/java/frc/robot/commands/RainBow.java @@ -0,0 +1,41 @@ +// 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; + +import edu.wpi.first.wpilibj2.command.Command; +import frc.robot.subsystems.Bougie; + +/* You should consider using the more terse Command factories API instead https://docs.wpilib.org/en/stable/docs/software/commandbased/organizing-command-based.html#defining-commands */ +public class RainBow extends Command { + /** Creates a new RainBow. */ + private Bougie bougie; + public RainBow(Bougie bougie) { + this.bougie = bougie; + addRequirements(bougie); + // 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() { + bougie.RainBow(); + } + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + bougie.RainBowStop(); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc/robot/subsystems/Bougie.java b/src/main/java/frc/robot/subsystems/Bougie.java new file mode 100644 index 0000000..9876824 --- /dev/null +++ b/src/main/java/frc/robot/subsystems/Bougie.java @@ -0,0 +1,38 @@ +// 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.subsystems; + +import com.ctre.phoenix.led.CANdle; +import com.ctre.phoenix.led.CANdleConfiguration; +import com.ctre.phoenix.led.RainbowAnimation; + +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class Bougie extends SubsystemBase { + CANdle candle = new CANdle(5); + CANdleConfiguration config = new CANdleConfiguration(); + RainbowAnimation rainbowAnim = new RainbowAnimation(1, 0.5, 64); + /** Creates a new Bougie. */ + public Bougie() { + config.brightnessScalar = 0.5; + candle.configAllSettings(config); + } + public void Rouge() { + candle.setLEDs(255, 0, 0); + } + public void Vert() { + candle.setLEDs(0, 255, 0); + } + public void Bleu() { + candle.setLEDs(0, 0, 255); + } + public void RainBow(){candle.animate(rainbowAnim);} + public void RainBowStop(){candle.animate(null);} + @Override + public void periodic() { + // This method will be called once per scheduler run + } +} +