Skip to content

Commit

Permalink
Merge pull request #10 from Merridew1/LEDS
Browse files Browse the repository at this point in the history
LEDs
  • Loading branch information
Merridew1 authored Dec 2, 2024
2 parents ca45398 + 6edd0bf commit 6e5fd85
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;
import edu.wpi.first.wpilibj2.command.WaitCommand;
Expand Down Expand Up @@ -72,7 +73,7 @@ private void configureButtonBindings() {
drivetrain.setDefaultCommand(drivetrain.driveCommand(driver));
driver.a().whileTrue(hatch.hatchUpCommand());
driver.a().whileTrue(hatch.hatchNeutralCommand());
driver.leftTrigger().whileTrue(intake.intakeCommand());
driver.leftTrigger().whileTrue(intake.intakeCommand(Color.kPurple, Color.kWhiteSmoke));
driver.rightTrigger().whileTrue(intake.outtakeCommand());
}

Expand Down
Empty file.
128 changes: 128 additions & 0 deletions src/main/java/frc/robot/subsystems/LEDs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package frc.robot.subsystems;

import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj2.command.SubsystemBase;

/**
* This is the class header for the LEDs Subsystem
*/
public class LEDs extends SubsystemBase {
private AddressableLEDBuffer controLedBuffer;
@SuppressWarnings("IOCheck")
private AddressableLED addressableLED;

/**
* constructs a LED Subsystem
*
* @param length length of the addressable LEDS
* @param port port ID for PWM
*/
public LEDs(int length, int port) {
controLedBuffer = new AddressableLEDBuffer(length);
addressableLED = new AddressableLED(port);

addressableLED.setLength(controLedBuffer.getLength());
addressableLED.setData(controLedBuffer);
addressableLED.start();
}

/**
* Get LED strip length
*
* @return number of LEDs
*/
public int getLength() {
return controLedBuffer.getLength();
}

/**
* Set individual LED color via HSV
*
* @param index the LED index to set
* @param h the h value [0-180)
* @param s the s value [0-255]
* @param v the v value [0-255]
*/
public void setHSV(int index, int h, int s, int v) {
controLedBuffer.setHSV(index, h, s, v);
}

/**
* Sets the LED output data.
*/
public void setData() {
addressableLED.setData(controLedBuffer);
}

/**
* Set individual LED color via RGB
*
* @param index the LED index to set
* @param r the r value [0-255]
* @param g the g value [0-255]
* @param b the b value [0-255]
*/
public void setRGB(int index, int r, int g, int b) {
controLedBuffer.setRGB(index, r, g, b);
}

/**
* Sets RGB Color of the entire LED strip
*
* @param r - [0 - 255]
* @param g - [0 - 255]
* @param b - [0 - 255]
*/
public void setRGB(int r, int g, int b) {
for (var i = 0; i < getLength(); i++) {
setRGB(i, r, g, b);
}
setData();
}

/**
* Set individual LED color via Color
*
* @param index the LED index to set
* @param color The color of the LED
*/
public void setColor(int index, Color color) {
controLedBuffer.setLED(index, color);
}

/**
* Sets the Color of the entire LED strip
*
* @param color color set for the LEDs
*/
public void setColor(Color color) {
for (var i = 0; i < getLength(); i++) {
setColor(i, color);
}
setData();
}

public Color getColor(int index) {
return controLedBuffer.getLED(index);
}

private int flashingDelay = 0;


public void flash(Color color, Color altColor) {
if (flashingDelay < 10) {
for (var i = 0; i < getLength(); i++) {
setColor(i, color);
}
} else {
for (var i = 0; i < getLength(); i++) {
setColor(i, altColor);
}
}
setData();
flashingDelay++;
flashingDelay %= 20;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package frc.robot.subsystems.ballMechanism;

import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.subsystems.LEDs;

public class ballMechanism extends SubsystemBase {
ballMechanismIO io;
ballMechanismInputsAutoLogged intakeAutoLogged = new ballMechanismInputsAutoLogged();
LEDs lights = new LEDs(9, 100);

public ballMechanism(ballMechanismIO io) {
this.io = io;
Expand All @@ -31,12 +34,13 @@ public boolean getOuttakeBeamBrakeStatus() {
return intakeAutoLogged.outtakeBeamBrake;
}

public Command intakeCommand() {
public Command intakeCommand(Color color, Color altColor) {
return Commands.startEnd(() -> {
setBallMotor(1);
}, () -> {
setBallMotor(0);
}, this).until(() -> getIntakeBeamBreakStatus()).unless(() -> getIntakeBeamBreakStatus());
}, this).until(() -> getIntakeBeamBreakStatus()).unless(() -> getIntakeBeamBreakStatus())
.andThen(() -> lights.flash(color, altColor));

}

Expand Down

0 comments on commit 6e5fd85

Please sign in to comment.