mirror of
https://github.com/Team4388/Robot-Essentials.git
synced 2026-06-09 08:48:02 -06:00
Add Blinken LED functionality
This commit is contained in:
@@ -14,6 +14,7 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
|
|||||||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||||
import frc4388.robot.commands.ExampleCommand;
|
import frc4388.robot.commands.ExampleCommand;
|
||||||
import frc4388.robot.subsystems.ExampleSubsystem;
|
import frc4388.robot.subsystems.ExampleSubsystem;
|
||||||
|
import frc4388.robot.subsystems.LED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The VM is configured to automatically run this class, and to call the
|
* The VM is configured to automatically run this class, and to call the
|
||||||
@@ -24,6 +25,7 @@ import frc4388.robot.subsystems.ExampleSubsystem;
|
|||||||
*/
|
*/
|
||||||
public class Robot extends TimedRobot {
|
public class Robot extends TimedRobot {
|
||||||
public static ExampleSubsystem m_subsystem = new ExampleSubsystem();
|
public static ExampleSubsystem m_subsystem = new ExampleSubsystem();
|
||||||
|
public static LED led = new LED();
|
||||||
public static OI m_oi;
|
public static OI m_oi;
|
||||||
|
|
||||||
Command m_autonomousCommand;
|
Command m_autonomousCommand;
|
||||||
|
|||||||
@@ -23,4 +23,6 @@ public class RobotMap {
|
|||||||
// number and the module. For example you with a rangefinder:
|
// number and the module. For example you with a rangefinder:
|
||||||
// public static int rangefinderPort = 1;
|
// public static int rangefinderPort = 1;
|
||||||
// public static int rangefinderModule = 1;
|
// public static int rangefinderModule = 1;
|
||||||
|
|
||||||
|
public static final int LED_SPARK_ID = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||||
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||||
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||||
|
/* the project. */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
package frc4388.robot.commands;
|
||||||
|
|
||||||
|
import frc4388.robot.Robot;
|
||||||
|
import frc4388.robot.constants.LEDPatterns;
|
||||||
|
|
||||||
|
import edu.wpi.first.wpilibj.command.Command;
|
||||||
|
|
||||||
|
public class setLEDPattern extends Command {
|
||||||
|
|
||||||
|
LEDPatterns pattern;
|
||||||
|
|
||||||
|
public setLEDPattern(LEDPatterns pattern) {
|
||||||
|
requires(Robot.led);
|
||||||
|
this.pattern = pattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called just before this Command runs the first time
|
||||||
|
@Override
|
||||||
|
protected void initialize() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called repeatedly when this Command is scheduled to run
|
||||||
|
@Override
|
||||||
|
protected void execute() {
|
||||||
|
Robot.led.setPattern(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make this return true when this Command no longer needs to run execute()
|
||||||
|
@Override
|
||||||
|
protected boolean isFinished() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called once after isFinished returns true
|
||||||
|
@Override
|
||||||
|
protected void end() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when another command which requires one or more of the same
|
||||||
|
// subsystems is scheduled to run
|
||||||
|
@Override
|
||||||
|
protected void interrupted() {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package frc4388.robot.constants;
|
||||||
|
|
||||||
|
public enum LEDPatterns {
|
||||||
|
// PALLETTE PATTERNS
|
||||||
|
RAINBOW_RAINBOW(-0.99f), PARTY_RAINBOW(-0.97f), OCEAN_RAINBOW(-0.95f), LAVA_RAINBOW(-0.93f), FOREST_RAINBOW(-0.91f),
|
||||||
|
RAINBOW_GLITTER(-0.89f), CONFETTI(-0.87f), RED_SHOT(-0.85f), BLUE_SHOT(-0.83f), WHITE_SHOT(-0.81f), RAINBOW_SINELON(-0.79f),
|
||||||
|
PARTY_SINELON(-0.77f), OCEAN_SINELON(-0.75f), LAVA_SINELON(-0.73f), FOREST_SINELON(-0.71f), RAINBOW_BPM(-0.69f),
|
||||||
|
PARTY_BPM(-0.67f), OCEAN_BPM(-0.65f), LAVA_BPM(-0.63f), FOREST_BPM(-0.61f), FIRE_MEDIUM(-0.59f), FIRE_LARGE(-0.57f),
|
||||||
|
RAINBOW_TWINKLES(-0.55f), PARTY_TWINKLES(-0.53f), OCEAN_TWINKLES(-0.51f), LAVA_TWINKLES(-0.49f), FOREST_TWINKLES(-0.47f),
|
||||||
|
RAINBOW_WAVES(-0.45f), PARTY_WAVES(-0.43f), OCEAN_WAVES(-0.41f), LAVA_WAVES(-0.39f), FOREST_WAVES(-0.37f),
|
||||||
|
RED_SCANNER(-0.35f), GRAY_SCANNER(-0.33f), RED_CHASE(-0.31f), BLUE_CHASE(-0.29f), GRAY_CHASE(-0.27f), RED_HEARTBEAT(-0.25f),
|
||||||
|
BLUE_HEARTBEAT(-0.23f), WHITE_HEARTBEAT(-0.21f), GRAY_HEARBEAT(-0.19f), RED_BREATH(-0.17f), BLUE_BREATH(-0.15f),
|
||||||
|
GRAY_BREATH(-0.13f), RED_STROBE(-0.11f), BLUE_STROBE(-0.09f), GOLD_STROBE(-0.07f), WHITE_STROBE(-0.05f),
|
||||||
|
|
||||||
|
// COLOR 1 PATTERNS
|
||||||
|
C1_END_TO_END(-0.03f), C1_SCANNER(-0.01f), C1_CHASE(0.01f), C1_HEARTBEAT_SLOW(0.03f), C1_HEARTBEAT_MEDIUM(0.05f),
|
||||||
|
C1_HEARTBEAT_FAST(0.07f), C1_BREATH_SLOW(0.09f), C1_BREATH_FAST(0.11f), C1_SHOT(0.13f), C1_STROBE(0.15f),
|
||||||
|
|
||||||
|
// COLOR 2 PATTERNS
|
||||||
|
C2_END_TO_END(0.17f), C2_SCANNER(0.19f), C2_CHASE(0.21f), C2_HEARTBEAT_SLOW(0.23f), C2_HEARTBEAT_MEDIUM(0.25f),
|
||||||
|
C2_HEARTBEAT_FAST(0.27f), C2_BREATH_SLOW(0.29f), C2_BREATH_FAST(0.31f), C2_SHOT(0.33f), C2_STROBE(0.35f),
|
||||||
|
|
||||||
|
// COLOR 1 AND 2 PATTERNS
|
||||||
|
C1C2_SPARKLE(0.37f), C2C1_SPARKLE(0.39f), C1C2_GRADIENT(0.41f), C1C2_BPM(0.43f), C1C2_BLEND(0.45f), C1C2_TWINKLES(0.51f),
|
||||||
|
C1C2_WAVES(0.53f), C1C2_SINELON(0.55f),
|
||||||
|
|
||||||
|
// SOLID COLORS
|
||||||
|
SOLID_PINK_HOT(0.57f), SOLID_RED_DARK(0.59f), SOLID_RED(0.61f), SOLID_RED_ORANGE(0.63f), SOLID_ORANGE(0.65f),
|
||||||
|
SOLID_GOLD(0.67f), SOLID_YELLOW(0.69f), SOLID_GREEN_LAWN(0.71f), SOLID_GREEN_LIME(0.73f), SOLID_GREEN_DARK(0.75f),
|
||||||
|
SOLID_GREEN(0.77f), SOLID_BLUE_GREEN(0.79f), SOLID_BLUE_AQUA(0.81f), SOLID_BLUE_SKY(0.83f), SOLID_BLUE_DARK(0.85f),
|
||||||
|
SOLID_BLUE(0.87f), SOLID_BLUE_VIOLET(0.89f), SOLID_VIOLET(0.91f), SOLID_WHITE(0.93f), SOLID_GRAY(0.95f),
|
||||||
|
SOLID_GRAY_DARK(0.97f), SOLID_BLACK(0.99f);
|
||||||
|
|
||||||
|
// GETTERS/SETTERS
|
||||||
|
private final float id;
|
||||||
|
LEDPatterns(float id) { this.id = id; }
|
||||||
|
public float getValue() { return id; }
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
package frc4388.robot.subsystems;
|
package frc4388.robot.subsystems;
|
||||||
|
|
||||||
import edu.wpi.first.wpilibj.command.Subsystem;
|
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||||
import frc4388.controller.XboxTriggerButton;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add your docs here.
|
* Add your docs here.
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
/* Copyright (c) 2018 FIRST. All Rights Reserved. */
|
||||||
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||||
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||||
|
/* the project. */
|
||||||
|
/*----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
package frc4388.robot.subsystems;
|
||||||
|
|
||||||
|
import frc4388.robot.RobotMap;
|
||||||
|
import frc4388.robot.constants.LEDPatterns;
|
||||||
|
import edu.wpi.first.wpilibj.Spark;
|
||||||
|
import edu.wpi.first.wpilibj.command.Subsystem;
|
||||||
|
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allows for the control of a 5v LED Strip using a Rev Robotics Blinkin LED Driver
|
||||||
|
*/
|
||||||
|
public class LED extends Subsystem {
|
||||||
|
|
||||||
|
public static float currentLED;
|
||||||
|
public static Spark LEDController;
|
||||||
|
|
||||||
|
public LED(){
|
||||||
|
LEDController = new Spark(RobotMap.LED_SPARK_ID);
|
||||||
|
setPattern(LEDPatterns.FOREST_WAVES);
|
||||||
|
LEDController.set(currentLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void periodic() {
|
||||||
|
LEDController.set(currentLED);
|
||||||
|
SmartDashboard.putNumber("LED", currentLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPattern(LEDPatterns pattern){
|
||||||
|
currentLED = pattern.getValue();
|
||||||
|
LEDController.set(currentLED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initDefaultCommand() {
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user