-
Notifications
You must be signed in to change notification settings - Fork 0
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' of https://github.com/redshiftrobotics/crescendo-…
- Loading branch information
Showing
4 changed files
with
60 additions
and
34 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,51 @@ | ||
package frc.robot.subsystems; | ||
|
||
import edu.wpi.first.wpilibj.AddressableLED; | ||
import edu.wpi.first.wpilibj.AddressableLEDBuffer; | ||
import edu.wpi.first.wpilibj.motorcontrol.Spark; | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import frc.robot.Constants.LightConstants; | ||
|
||
public class LightStrip extends SubsystemBase { | ||
private AddressableLED ledStrip; | ||
private AddressableLEDBuffer ledBuffer; | ||
/** | ||
* The LED controller PWM signal from 1000-2000us, which is identical to a Spark | ||
* servo. So, we use the Spark class. | ||
* -1 corresponds to 1000us | ||
* 0 corresponds to 1500us | ||
* +1 corresponds to 2000us | ||
*/ | ||
private Spark ledStrip; | ||
private double pattern; | ||
|
||
public LightStrip(AddressableLED ledstrip) { | ||
/** | ||
* Creates a new LightStrip subsystem. | ||
* | ||
* @param ledstrip The 'spark' representing the Blinkin | ||
*/ | ||
public LightStrip(Spark ledstrip) { | ||
ledStrip = ledstrip; | ||
ledBuffer = new AddressableLEDBuffer(LightConstants.LED_QUANTITY); | ||
|
||
// Docs say this is an expensive operation so future maintainers should avoid | ||
// modifying this excessibely | ||
ledStrip.setLength(ledBuffer.getLength()); | ||
ledStrip.setData(ledBuffer); | ||
} | ||
|
||
ledStrip.start(); | ||
/** | ||
* Creates a new LightStrip subsystem. | ||
* | ||
* @param pwmPort The port number for the blinkin | ||
*/ | ||
public LightStrip(int pwmPort) { | ||
ledStrip = new Spark(pwmPort); | ||
} | ||
|
||
public void setColor(int r, int g, int b) { | ||
for (int i = 0; i < ledBuffer.getLength(); i++) { | ||
ledBuffer.setRGB(i, r, g, b); | ||
} | ||
/** | ||
* Sets the blinkin to a pattern | ||
* | ||
* @param pattern Pattern ID to use. Consult section 5 of the blinkin manual. | ||
* @link https://www.revrobotics.com/content/docs/REV-11-1105-UM.pdf | ||
*/ | ||
public void setPattern(double pattern) { | ||
this.pattern = pattern; | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
ledStrip.setData(ledBuffer); | ||
// System.out.println("*** Subsystem setting pattern to pattern number " + | ||
// pattern); | ||
ledStrip.set(pattern); | ||
} | ||
} |