diff --git a/src/main/java/frc/robot/commands/RainBowAnim.java b/src/main/java/frc/robot/commands/RainBowAnim.java new file mode 100644 index 0000000..d08131f --- /dev/null +++ b/src/main/java/frc/robot/commands/RainBowAnim.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.Led; + +/* 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 RainBowAnim extends Command { + private Led led; + /** Creates a new RainBowAnim. */ + public RainBowAnim(Led led) { + this.led = led; + addRequirements(led); + // Use addRequirements() here to declare subsystem dependencies. + } + + // Called when the command is initially scheduled. + @Override + public void initialize() { + led.RainBow(); + } + + // Called every time the scheduler runs while the command is scheduled. + @Override + public void execute() {} + + // Called once the command ends or is interrupted. + @Override + public void end(boolean interrupted) { + led.RainBowStop(); + } + + // Returns true when the command should end. + @Override + public boolean isFinished() { + return false; + } +} diff --git a/src/main/java/frc/robot/subsystems/Led.java b/src/main/java/frc/robot/subsystems/Led.java new file mode 100644 index 0000000..d38f5da --- /dev/null +++ b/src/main/java/frc/robot/subsystems/Led.java @@ -0,0 +1,87 @@ +// 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 java.util.Optional; + +import com.ctre.phoenix.led.CANdle; +import com.ctre.phoenix.led.RainbowAnimation; + +import edu.wpi.first.wpilibj.DriverStation; +import edu.wpi.first.wpilibj2.command.SubsystemBase; + +public class Led extends SubsystemBase { + CANdle CANDle = new CANdle(7); + RainbowAnimation rainbowAnim = new RainbowAnimation(); + public void bleu(){ + CANDle.setLEDs(0, 0, 255); + } + public void Vert(){ + CANDle.setLEDs(0,255, 0); + } + public void Rouge(){ + CANDle.setLEDs(255,0, 0); + } + public void RainBow(){ + CANDle.animate(rainbowAnim); + } + public void RainBowStop(){ + CANDle.animate(null); + } + public boolean Equipe(){ + Optional alliance = DriverStation.getAlliance(); + if(alliance.get() == DriverStation.Alliance.Blue){ + return true; + } + else{ + return false; + } + } + /** Creates a new Led. */ + public Led() {} + + @Override + public void periodic() { + double temps = DriverStation.getMatchTime(); + if(temps > 20 && temps < 30){ + Vert(); + } + if(Equipe()){ + if(temps > 30 && temps < 55){ + bleu(); + } + else if(temps > 30 && temps < 80){ + Rouge(); + } + else if(temps > 80 && temps < 105){ + bleu(); + } + else if(temps > 105 && temps < 130){ + Rouge(); + } + else{ + RainBow(); + } + } + else{ + if(temps > 30 && temps < 55){ + Rouge(); + } + else if(temps > 30 && temps < 80){ + bleu(); + } + else if(temps > 80 && temps < 105){ + Rouge(); + } + else if(temps > 105 && temps < 130){ + bleu(); + } + else{ + RainBow(); + } + } + // This method will be called once per scheduler run + } +}