Skip to content

Commit eb0c5fc

Browse files
committed
added the game in LEDSubsystem
1 parent 0f3cc2a commit eb0c5fc

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

src/main/java/frc/robot/constants/LEDConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public class LEDConstants {
3939
// Climb LED Colors
4040
public static final Color kWaitingForCage = Color.kRed;
4141
public static final Color kHasCage = Color.kGreen;
42-
public static final Color[] gameColors = {
42+
public static final Color[] kGameColors = {
43+
Color.kBlack, // a dummy color
4344
Color.kDarkRed,
4445
Color.kDarkGreen,
4546
Color.kDarkBlue,

src/main/java/frc/robot/subsystems/led/LEDSubsystem.java

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ public class LEDSubsystem extends MeasurableSubsystem {
4242
private boolean autoPlacing = false;
4343
private boolean isLimiting = false;
4444

45+
// game stuff
46+
private int[] BottomUnits = new int[LEDConstants.kStripLength];
47+
private int[] TopUnits = new int[LEDConstants.kStripLength];
48+
4549
public LEDSubsystem(LEDIO io) {
4650
this.io = io;
4751
}
@@ -62,9 +66,10 @@ public void setState(LEDStates state) {
6266
io.setStrip(LEDConstants.kHasCage);
6367
break;
6468
case CLIMB_UP:
65-
base =
66-
LEDPattern.gradient(GradientType.kContinuous, Color.kLightGoldenrodYellow, Color.kBlack)
67-
.scrollAtRelativeSpeed(Percent.per(Seconds).of(1));
69+
// base =
70+
// LEDPattern.gradient(GradientType.kContinuous, Color.kLightGoldenrodYellow, Color.kBlack)
71+
// .scrollAtRelativeSpeed(Percent.per(Seconds).of(1));
72+
io.setOff();
6873
break;
6974
default:
7075
break;
@@ -189,6 +194,58 @@ private void buildBase() {
189194
base = getAlgea.overlayOn(place.overlayOn(level.overlayOn(algea.overlayOn(coral))));
190195
}
191196

197+
//game stuff
198+
private void advanceUnits() {
199+
for (int i = 0; i <= LEDConstants.kStripLength-1; i++) {
200+
BottomUnits[i + 1] = BottomUnits[i];
201+
TopUnits[i] = TopUnits[i + 1];
202+
if (i == 0)
203+
BottomUnits[i] = 0;
204+
if (i == LEDConstants.kStripLength)
205+
TopUnits[i] = 0;
206+
if (TopUnits[i] != 0 && BottomUnits[i] != 0) {
207+
if (BottomUnits[i] == TopUnits[i]) {
208+
BottomUnits[i] = 0;
209+
TopUnits[i] = 0;
210+
} else if (BottomUnits[i] > TopUnits[i] || (BottomUnits[i] == 1 && TopUnits[i] == 3)) {
211+
TopUnits[i] = 0;
212+
} else {
213+
BottomUnits[i] = 0;
214+
}
215+
}
216+
if (TopUnits[i + 1] != 0 && BottomUnits[i] != 0) {
217+
if (BottomUnits[i] == TopUnits[i + 1]) {
218+
BottomUnits[i] = 0;
219+
TopUnits[i + 1] = 0;
220+
} else if (BottomUnits[i] > TopUnits[i + 1] || (BottomUnits[i] == 1 && TopUnits[i + 1] == 3)) {
221+
TopUnits[i + 1] = 0;
222+
} else {
223+
BottomUnits[i + 1] = 0;
224+
}
225+
}
226+
}
227+
}
228+
229+
private void displayUnits() {
230+
for (int i = 0; i <= LEDConstants.kStripLength-1; i++) {
231+
io.setLED(i, LEDConstants.kGameColors[BottomUnits[i]]);
232+
if (TopUnits[i] != 0){
233+
io.setLED(i, LEDConstants.kGameColors[TopUnits[i] + 3]);
234+
}
235+
}
236+
}
237+
238+
public void addGameUnit(boolean isBottom, int unitNum) {
239+
// the unitNum starts at 1 and ends at 3. if you use anything else, it will be ignored
240+
if (unitNum >= 1 && unitNum <= 3) {
241+
if (isBottom){
242+
BottomUnits[0] = unitNum;
243+
} else {
244+
TopUnits[LEDConstants.kStripLength - 1] = unitNum;
245+
}
246+
}
247+
}
248+
192249
public void periodic() {
193250
switch (currState) {
194251
case OFF:
@@ -205,6 +262,11 @@ public void periodic() {
205262
break;
206263
case CLIMB_EMPTY:
207264
break;
265+
case CLIMB_FULL:
266+
break;
267+
case CLIMB_UP:
268+
advanceUnits();
269+
displayUnits();
208270
}
209271
io.updateLEDs();
210272
}

0 commit comments

Comments
 (0)