Skip to content

Commit

Permalink
made rainbow command work with params, and fixed var name
Browse files Browse the repository at this point in the history
  • Loading branch information
Nummun14 committed Nov 13, 2024
1 parent f10e39c commit f6964e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,22 @@ void alternateColor(Color firstColor, Color secondColor, double intervalSeconds)

@Override
void rainbow(double brightness, double speed) {
int adjustedBrightness = (int) (brightness * 255);
int hueIncrement = (int) (speed * 3);

for (int led = 0; led < numberOfLEDs; led++) {
final int hue = (int) (rainbowFirstPixelHue + (led * 180 / numberOfLEDs) % 180);
LED_BUFFER.setHSV(led + indexOffset, hue, 255, 128);
LED_BUFFER.setHSV(led + indexOffset, hue, 255, adjustedBrightness);
}

if (inverted) {
rainbowFirstPixelHue -= 3;
rainbowFirstPixelHue -= hueIncrement;
if (rainbowFirstPixelHue < 0)
rainbowFirstPixelHue += 180;
return;
} else {
rainbowFirstPixelHue += hueIncrement;
rainbowFirstPixelHue %= 180;
}
rainbowFirstPixelHue += 3;
rainbowFirstPixelHue %= 180;
}

@Override
Expand All @@ -168,12 +172,12 @@ void resetLEDSettings() {
}

private void checkIfBreathingHasHitEnd(int amountOfBreathingLEDs, boolean shouldLoop, boolean inverted, LarsonAnimation.BounceMode bounceMode) {
int bounceModeThing = switch (bounceMode) {
int bounceModeAddition = switch (bounceMode) {
case Back -> amountOfBreathingLEDs;
case Center -> amountOfBreathingLEDs / 2;
default -> 0;
};
if (inverted ? (lastBreatheLED < indexOffset + bounceModeThing) : (lastBreatheLED >= numberOfLEDs + indexOffset + bounceModeThing)) {
if (inverted ? (lastBreatheLED < indexOffset + bounceModeAddition) : (lastBreatheLED >= numberOfLEDs + indexOffset + bounceModeAddition)) {
if (!shouldLoop) {
getDefaultCommand().schedule();
return;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/trigon/hardware/misc/leds/LEDStrip.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void resetLEDSettings() {
* @param cycleTimeSeconds the time it takes for a full cycle of the breathing
* @param shouldLoop whether the breathing should loop
* @param inverted whether the breathing should be inverted
* @param bounceMode the bounce mode of the breathing, only for CANdleLEDStrip
* @param bounceMode the bounce mode of the breathing
*/
abstract void breathe(Color color, int breathingLEDs, double cycleTimeSeconds, boolean shouldLoop, boolean inverted, LarsonAnimation.BounceMode bounceMode);

Expand Down Expand Up @@ -90,8 +90,8 @@ void resetLEDSettings() {
/**
* Displays a rainbow pattern on the LED strip.
*
* @param brightness the brightness of the rainbow, only for CANdleLEDStrip
* @param speed the speed of the rainbow, only for CANdleLEDStrip
* @param brightness the brightness of the rainbow, must be a number between 0 and 1
* @param speed the speed of the rainbow
*/
abstract void rainbow(double brightness, double speed);

Expand Down

0 comments on commit f6964e9

Please sign in to comment.