-
Notifications
You must be signed in to change notification settings - Fork 1
/
LEDSubsystem.java
123 lines (107 loc) · 3.24 KB
/
LEDSubsystem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package team.gif.robot.subsystems;
import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import team.gif.robot.Constants;
import team.gif.robot.RobotMap;
public class LEDSubsystem extends SubsystemBase {
private static AddressableLED led;
private static AddressableLEDBuffer ledBuffer;
private final int [] HP = {0,0,0};
private final int [] GamePiece = {0,0,0};
private final int [] WheelState = {0,0,0};
public LEDSubsystem() {
super();
//initializes by inputting PWM port number from Roborio
led = new AddressableLED(RobotMap.LED_PWM_PORT);
//initialize by inputting length of LED (# of LED)
ledBuffer = new AddressableLEDBuffer(Constants.LED.NUM_LEDS_TOTAL);
led.setLength(ledBuffer.getLength());
// Set the data
led.setData(ledBuffer);
led.start();
}
/**
* Sets the specified LED to the RGB values
* @param r red
* @param g green
* @param b blue
*/
public void setLEDHPColor(int r, int g, int b) {
HP[0] = r;
HP[1] = g;
HP[2] = b;
}
/**
* Assigns the color of the LEDs to green to indicate the game piece is in
*/
public void setLEDGamePieceColor() {
GamePiece[0] = 0;
GamePiece[1] = 255;
GamePiece[2] = 0;
}
/**
* Assigns the color of the LEDs to null to indicate the game piece is not in
*/
public void clearLEDGamePieceColor() {
GamePiece[0] = 0;
GamePiece[1] = 0;
GamePiece[2] = 0;
}
/**
* Assigns the color of the LEDs to null to indicate the wheels are in
*/
public void LEDWheelsIn() {
WheelState[0] = 0;
WheelState[1] = 0;
WheelState[2] = 0;
}
/**
* Assigns the color of the LEDs to blue to indicate the wheels are out
*/
public void LEDWheelsOut() {
WheelState[0] = 0;
WheelState[1] = 0;
WheelState[2] = 255;
}
/**
* Assigns the color of the LEDs to red to indicate an error on autoAlign
*/
public void setLEDAutoAlignError() {
GamePiece[0] = 255;
GamePiece[1] = 255;
GamePiece[2] = 255;
}
public void setLEDAutoCollectActive() {
HP[0] = 255;
HP[1] = 0;
HP[2] = 0;
}
public void setLEDFullSpeed() {
HP[0] = 255;
HP[1] = 0;
HP[2] = 0;
}
public void setLEDNonFullSpeed() {
HP[0] = 0;
HP[1] = 255;
HP[2] = 0;
}
/**
* Sets the colors of the LEDs
*/
public void setColors() {
for (int i = 0; i < RobotMap.HP_LEDS.length; i++) {
ledBuffer.setRGB(RobotMap.HP_LEDS[i],HP[0],HP[1], HP[2]);
led.setData(ledBuffer);
}
for (int j = 0; j < RobotMap.GAME_PIECE_LEDS.length; j++) {
ledBuffer.setRGB(RobotMap.GAME_PIECE_LEDS[j], GamePiece[0], GamePiece[1], GamePiece[2]);
led.setData(ledBuffer);
}
for (int k = 0; k < RobotMap.WHEEL_STATE_LEDS.length; k++) {
ledBuffer.setRGB(RobotMap.WHEEL_STATE_LEDS[k], WheelState[0], WheelState[1], WheelState[2]);
led.setData(ledBuffer);
}
}
}