Skip to content

Commit

Permalink
Rainbow LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
danjburke12 committed Jul 28, 2024
1 parent 886463e commit 1db41a2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ private void setRBGFromGradient(int index, double red, double green, double blue
mLEDBuffer.setRGB(index, (int) (red * brightness), (int) (blue * brightness), (int) (green * brightness));
}

private void setHSV(int index, int hue, int saturation, int value) {
var brightness = mBrightness[index];
mLEDBuffer.setHSV(index, hue, saturation, value);
}

public void update() {
for (var i = 0; i < mColors.length; i++) {
var color = mColors[i];
Expand Down
60 changes: 43 additions & 17 deletions src/main/java/com/team1701/robot/subsystems/leds/LED.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.team1701.robot.subsystems.leds;

import com.team1701.lib.drivers.leds.LEDController;
import com.team1701.robot.Configuration;
import com.team1701.robot.states.RobotState;
import edu.wpi.first.math.MathUtil;
import edu.wpi.first.wpilibj.DriverStation;
Expand Down Expand Up @@ -60,28 +59,55 @@ private void setStrobe(Color color) {
mLEDController.setAll(tick % 2 == 0 ? color : Color.kWhite);
}

private void setDisabledLEDStates() {
var color = Configuration.isBlueAlliance() ? LEDColors.kDisabledBlue : LEDColors.kDisabledRed;
var cylonColumn = (int) ((Timer.getFPGATimestamp() * kCylonFrequency) % ((kTopLEDsPerRow - 1) * 2));
if (cylonColumn >= kTopLEDsPerRow) {
cylonColumn = (kTopLEDsPerRow - 1) * 2 - cylonColumn;
}
private void setRainbow() {
var tick = (int) (Timer.getFPGATimestamp() * 60);
var hue = tick % 180;
// for (var row = 0; row < kTopLEDsRowCount; row++) {
// var start = row * kTopLEDsPerRow;
// mLEDController.setRange(start, start + 3, Color.fromHSV(hue, 255, 128));
// }

mLEDController.setAll(Color.kBlack);
for (var row = 0; row < kTopLEDsRowCount; row++) {
var rowStart = row * kTopLEDsPerRow;
var rowEnd = rowStart + kTopLEDsPerRow - 1;
var column = row % 2 == 0 ? rowStart + cylonColumn : rowEnd - cylonColumn;
mLEDController.set(column, color);
if (column > rowStart) {
mLEDController.set(column - 1, color, 0.25);
}
if (column < rowEnd) {
mLEDController.set(column + 1, color, 0.25);
if (row % 2 == 0) {
for (var i = 0; i < kTopLEDsPerRow; i++) {
mLEDController.set(i + row * kTopLEDsPerRow, Color.fromHSV((hue + i * 10) % 180, 255, 128));
}
} else {
for (var i = 0; i < kTopLEDsPerRow; i++) {
mLEDController.set(
kTopLEDsPerRow - i - 1 + row * kTopLEDsPerRow,
Color.fromHSV((hue + i * 10) % 180, 255, 128));
}
}
}
}

// private void setDisabledLEDStates() {
// var color = Configuration.isBlueAlliance() ? LEDColors.kDisabledBlue : LEDColors.kDisabledRed;
// var cylonColumn = (int) ((Timer.getFPGATimestamp() * kCylonFrequency) % ((kTopLEDsPerRow - 1) * 2));
// if (cylonColumn >= kTopLEDsPerRow) {
// cylonColumn = (kTopLEDsPerRow - 1) * 2 - cylonColumn;
// }

// mLEDController.setAll(Color.kBlack);
// for (var row = 0; row < kTopLEDsRowCount; row++) {
// var rowStart = row * kTopLEDsPerRow;
// var rowEnd = rowStart + kTopLEDsPerRow - 1;
// var column = row % 2 == 0 ? rowStart + cylonColumn : rowEnd - cylonColumn;
// mLEDController.set(column, color);
// if (column > rowStart) {
// mLEDController.set(column - 1, color, 0.25);
// }
// if (column < rowEnd) {
// mLEDController.set(column + 1, color, 0.25);
// }
// }
// }

private void setDisabledLEDStates() {
setRainbow();
}

private void setScoringLEDStates() {
var state = mRobotState.getShootingState();
if (state.isShooting) {
Expand Down

0 comments on commit 1db41a2

Please sign in to comment.