Skip to content

Commit

Permalink
add AddressableLightStrip
Browse files Browse the repository at this point in the history
  • Loading branch information
quackitsquinn committed Mar 22, 2024
1 parent 8fa7f8c commit ed6ba29
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,4 +233,13 @@ public static class Camera {
/** The camera id for the intake camera. */
public static final int INTAKE_CAMERA_ID = 0;
}

/** The constants for the light strips */
public static class LightStrips {
/** The PWM ID for the underglow light strip */
public static final int UNDERGLOW_PWM_ID = 0;

/** The count of leds for the underglow light strip. */
public static final int UNDERGLOW_LED_COUNT = 60;
}
}
6 changes: 6 additions & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import frc.robot.commands.mailbox.FireNoteRoutine;
import frc.robot.commands.mailbox.FireNoteRoutineNoLimitSwitch;
import frc.robot.commands.mailbox.RunBelts;
import frc.robot.subsystems.AddressableLightStrip;
import frc.robot.subsystems.Camera;
import frc.robot.subsystems.Climber;
import frc.robot.subsystems.Drive;
Expand Down Expand Up @@ -229,6 +230,11 @@ public class RobotContainer {
public static SetDrivePerspectiveFieldOriented setDrivePerspectiveFieldOriented =
new SetDrivePerspectiveFieldOriented();

/** Singleton instance of {@link AddressableLightStrip} for the whole robot. */
public static AddressableLightStrip robotUnderglow =
new AddressableLightStrip(
Constants.LightStrips.UNDERGLOW_PWM_ID, Constants.LightStrips.UNDERGLOW_LED_COUNT);

/**
* Singleton instance of {@link SetDrivePerspectiveFieldOrientedHeadingSnapping} for the whole
* robot.
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/frc/robot/subsystems/AddressableLightStrip.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// 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.

/*
* Asimov's Laws:
* The First Law: A robot may not injure a human being or, through inaction, allow a human being to come to harm.
* The Second Law: A robot must obey the orders given it by human beings except where such orders would conflict with the First Law.
* The Third Law: A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.
*/

package frc.robot.subsystems;

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

public class AddressableLightStrip extends SubsystemBase {

private final AddressableLED ledStrip;
private final AddressableLEDBuffer buffer;

/**
* Creates a new AddressableLightStrip
*
* @param pwmPort The PWM port for the light strip.
* @param lightCount The count of lights on the switch
*/
public AddressableLightStrip(int pwmPort, int lightCount) {
this.ledStrip = new AddressableLED(pwmPort);
this.buffer = new AddressableLEDBuffer(lightCount);
this.ledStrip.setLength(lightCount);
}

/**
* Sets a light on the light strip to a color in RGB.
*
* @param lightNumber The light number
* @param r The red component
* @param g The green component
* @param b The blue component
*/
public void setRgbLight(int lightNumber, int r, int g, int b) {
this.buffer.setRGB(lightNumber, r, g, b);
}

/**
* Sets a light on the light strip to a color in HSV
*
* @param lightNumber The light number
* @param h The hue component
* @param s The saturation component
* @param v The value component
*/
public void setHSVLight(int lightNumber, int h, int s, int v) {
this.buffer.setHSV(lightNumber, h, s, v);
}

/** Fushes the buffer to the light strip. */
public void flush() {
this.ledStrip.setData(this.buffer);
}

/** Starts the light strip. */
public void startLights() {
this.ledStrip.start();
}

/** Stops the light strip. */
public void stopLights() {
this.ledStrip.stop();
}

@Override
public void periodic() {
// This method will be called once per scheduler run
}
}

0 comments on commit ed6ba29

Please sign in to comment.