-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into GearFox-ReleaseCleanup
- Loading branch information
Showing
7 changed files
with
156 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/frc/robot/commands/LEDControllerCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// 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.wpilibj.Timer; | ||
import edu.wpi.first.wpilibj2.command.CommandBase; | ||
import frc.robot.subsystems.LedSubsystem; | ||
|
||
public class LEDControllerCommand extends CommandBase { | ||
/** Creates a new LEDControllerCommand. */ | ||
LedSubsystem m_led; | ||
Timer m_timer; | ||
public LEDControllerCommand(LedSubsystem led) { | ||
// Use addRequirements() here to declare subsystem dependencies. | ||
m_led = led; | ||
m_timer = new Timer(); | ||
addRequirements(led); | ||
} | ||
|
||
// Called when the command is initially scheduled. | ||
@Override | ||
public void initialize() { | ||
m_timer.reset(); | ||
m_timer.start(); | ||
} | ||
|
||
// Called every time the scheduler runs while the command is scheduled. | ||
@Override | ||
public void execute() { | ||
if (m_timer.hasElapsed(10)) { | ||
m_led.nextAnimation(); | ||
m_timer.restart(); | ||
} | ||
} | ||
|
||
// 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package frc.robot.subsystems; | ||
|
||
import com.ctre.phoenix.led.Animation; | ||
import com.ctre.phoenix.led.CANdle; | ||
import com.ctre.phoenix.led.ColorFlowAnimation; | ||
import com.ctre.phoenix.led.FireAnimation; | ||
import com.ctre.phoenix.led.LarsonAnimation; | ||
import com.ctre.phoenix.led.RainbowAnimation; | ||
import com.ctre.phoenix.led.ColorFlowAnimation.Direction; | ||
import com.ctre.phoenix.led.LarsonAnimation.BounceMode; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
public class LedSubsystem extends SubsystemBase { | ||
private final CANdle m_candle; | ||
private final int m_numLED = 400; | ||
private Animations m_currentAnimation = Animations.RAINBOW; | ||
|
||
private final Animation m_rainbow = new RainbowAnimation(1.0, 0.5, m_numLED); | ||
private final Animation m_red = new ColorFlowAnimation(255, 0, 0, 0, 0.5, m_numLED, Direction.Forward); | ||
private final Animation m_blue = new ColorFlowAnimation(0, 255, 0, 0, 0.5, m_numLED, Direction.Forward); | ||
private final Animation m_fire = new FireAnimation(1.0, 0.5, m_numLED, 0.25, 0.25); | ||
private final Animation m_larson = new LarsonAnimation(255, 0, 0, 0, 0.5, m_numLED, BounceMode.Front, 20); | ||
|
||
public enum Animations { | ||
RAINBOW, | ||
RED, | ||
BLUE, | ||
FIRE, | ||
LARSON | ||
} | ||
|
||
public LedSubsystem(int id) { | ||
m_candle = new CANdle(id); | ||
m_candle.animate(m_rainbow); | ||
} | ||
|
||
public void nextAnimation() { | ||
switch (m_currentAnimation) { | ||
case BLUE: | ||
m_currentAnimation = Animations.FIRE; | ||
break; | ||
case FIRE: | ||
m_currentAnimation = Animations.LARSON; | ||
break; | ||
case LARSON: | ||
m_currentAnimation = Animations.RAINBOW; | ||
break; | ||
case RAINBOW: | ||
m_currentAnimation = Animations.RED; | ||
break; | ||
case RED: | ||
m_currentAnimation = Animations.BLUE; | ||
break; | ||
default: | ||
m_currentAnimation = Animations.RAINBOW; | ||
break; | ||
|
||
} | ||
} | ||
|
||
public void setAnimation(Animations animation) { | ||
m_currentAnimation = animation; | ||
} | ||
|
||
public Animations getAnimation() { | ||
return m_currentAnimation; | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
switch(m_currentAnimation){ | ||
case BLUE: | ||
m_candle.animate(m_blue); | ||
break; | ||
case FIRE: | ||
m_candle.animate(m_fire); | ||
break; | ||
case LARSON: | ||
m_candle.animate(m_larson); | ||
break; | ||
case RAINBOW: | ||
m_candle.animate(m_rainbow); | ||
break; | ||
case RED: | ||
m_candle.animate(m_red); | ||
break; | ||
default: | ||
m_candle.setLEDs(255, 0, 255); | ||
break; | ||
|
||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters