Skip to content

Instantly share code, notes, and snippets.

@zippy36jr
Created February 26, 2020 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zippy36jr/bf8390952567e09e4120259c0afb05b4 to your computer and use it in GitHub Desktop.
Save zippy36jr/bf8390952567e09e4120259c0afb05b4 to your computer and use it in GitHub Desktop.
package frc.robot.subsystems;
import java.util.Random;
import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
//TODO: Clean this mess up
public class Lighting extends SubsystemBase {
public int LED_COUTN1 = 100;
public double ledBufferLen;
AddressableLED led1;
AddressableLEDBuffer ledBuffer;
public Lighting()
{
led1 = new AddressableLED(9);
ledBuffer = new AddressableLEDBuffer(LED_COUTN1);
led1.setLength(ledBuffer.getLength());
led1.setData(ledBuffer);
led1.start();
ledBufferLen = ledBuffer.getLength();
}
@Override
public void periodic() {
showAnimationSeq();
}
private void showAnimationSeq()
{
quickFill(Color.kGold, 0.02);
quickFill(Color.kBlue, 0.02);
quickFill(Color.kDarkTurquoise, 0.02);
clearStrip();
alternatingColors(Color.kGold, Color.kBlue);
pause(0.5);
alternatingColors(Color.kBlue, Color.kGold);
pause(0.5);
alternatingColors(Color.kGold, Color.kBlue);
pause(0.5);
alternatingColors(Color.kBlue, Color.kGold);
pause(0.5);
alternatingColors(Color.kGold, Color.kBlue);
pause(0.5);
alternatingColors(Color.kBlue, Color.kGold);
clearStrip();
fadeToColor(100);
fadeFromColor(100);
fadeToColor(50);
fadeFromColor(50);
middleFill(Color.kDeepPink);
middleFill(Color.kFirstBlue);
fillAtRandom();
clearStrip();
}
private void pause(double time)
{
Timer.delay(time);
}
private void clearStrip()
{
for(int i = 0; i < ledBuffer.getLength(); i++)
{
ledBuffer.setRGB(i, 0, 0, 0);
}
led1.setData(ledBuffer);
}
private void fadeFromColor(int h)
{
for(int i = 255; i > 0; i-=15)
{
for(int j = 0; j < ledBuffer.getLength(); j++)
{
ledBuffer.setHSV(j, h, 255, i);
}
led1.setData(ledBuffer);
pause(0.1);
}
clearStrip();
}
private void fadeToColor(int h)
{
for(int i = 0; i < 255; i+=15)
{
for(int j = 0; j < ledBuffer.getLength(); j++)
{
ledBuffer.setHSV(j, h, 255, i);
}
led1.setData(ledBuffer);
pause(0.1);
}
}
private void quickFill(Color c, double wait)
{
for(int i = 0; i < ledBuffer.getLength(); i++)
{
ledBuffer.setLED(i, c);
led1.setData(ledBuffer);
Timer.delay(wait);
}
}
private void alternatingColors(Color c1, Color c2)
{
for(int i = 0; i < ledBuffer.getLength() - 1; i++)
{
if(i % 2 == 0)
{
ledBuffer.setLED(i, c1);
}
else
{
ledBuffer.setLED(i, c2);
}
}
led1.setData(ledBuffer);
}
private void middleFill(Color c)
{
for(int i = 0; i < ((ledBuffer.getLength() - 1) / 2); i++)
{
ledBuffer.setLED(ledBuffer.getLength()/2 + i, c);
ledBuffer.setLED(ledBuffer.getLength()/2 - i, c);
led1.setData(ledBuffer);
Timer.delay(0.05);
}
for(int i = 0; i < (ledBuffer.getLength() / 2); i++)
{
ledBuffer.setRGB(i, 0,0,0);
ledBuffer.setRGB((ledBuffer.getLength() -1) - i, 0,0,0);
led1.setData(ledBuffer);
Timer.delay(0.05);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment