|
|
|
@ -29,16 +29,16 @@ void LEDChaseEffect::update(void) {
|
|
|
|
|
}
|
|
|
|
|
last_update_ = now;
|
|
|
|
|
|
|
|
|
|
// The red LED is at `pos`; the blue one follows behind. `chase_sign` is either +1 or
|
|
|
|
|
// -1; `chase_pixels` is the gap between them.
|
|
|
|
|
int8_t pos2 = pos - (chase_sign * chase_pixels);
|
|
|
|
|
// The red LED is at `pos_`; the blue one follows behind. `direction_` is
|
|
|
|
|
// either +1 or -1; `distance_` is the gap between them.
|
|
|
|
|
int8_t pos2 = pos_ - (direction_ * distance_);
|
|
|
|
|
|
|
|
|
|
// First, we turn off the LEDs that were turned on in the previous update. `pos` is
|
|
|
|
|
// always in the valid range (0 <= pos < LED_COUNT), but after it changes direction, for
|
|
|
|
|
// the first few updates, `pos2` will be out of bounds. Since it's an unsigned integer,
|
|
|
|
|
// even when it would have a value below zero, it underflows and so one test is good for
|
|
|
|
|
// both ends of the range.
|
|
|
|
|
::LEDControl.setCrgbAt(pos, CRGB(0, 0, 0));
|
|
|
|
|
// First, we turn off the LEDs that were turned on in the previous update.
|
|
|
|
|
// `pos_` is always in the valid range (0 <= pos_ < LED_COUNT), but after it
|
|
|
|
|
// changes direction, for the first few updates, `pos2` will be out of bounds.
|
|
|
|
|
// Since it's an unsigned integer, even when it would have a value below zero,
|
|
|
|
|
// it underflows and so one test is good for both ends of the range.
|
|
|
|
|
::LEDControl.setCrgbAt(pos_, CRGB(0, 0, 0));
|
|
|
|
|
if (pos2 < LED_COUNT)
|
|
|
|
|
::LEDControl.setCrgbAt(pos2, CRGB(0, 0, 0));
|
|
|
|
|
|
|
|
|
@ -48,18 +48,18 @@ void LEDChaseEffect::update(void) {
|
|
|
|
|
// it back in bounds. When this happens, the blue light "jumps" behind the red one, and
|
|
|
|
|
// will be out of bounds. The simplest way to do this is to assign it a value that is
|
|
|
|
|
// known to be invalid (LED_COUNT).
|
|
|
|
|
pos += chase_sign;
|
|
|
|
|
if (pos < LED_COUNT && pos > 0) {
|
|
|
|
|
pos2 += chase_sign;
|
|
|
|
|
pos_ += direction_;
|
|
|
|
|
if (pos_ < LED_COUNT && pos_ > 0) {
|
|
|
|
|
pos2 += direction_;
|
|
|
|
|
} else {
|
|
|
|
|
chase_sign = -chase_sign;
|
|
|
|
|
pos += chase_sign;
|
|
|
|
|
direction_ = -direction_;
|
|
|
|
|
pos_ += direction_;
|
|
|
|
|
pos2 = LED_COUNT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Last, we turn on the LEDs at their new positions. As before, the blue light (pos2) is
|
|
|
|
|
// only set if it's in the valid LED range.
|
|
|
|
|
::LEDControl.setCrgbAt(pos, CRGB(255, 0, 0));
|
|
|
|
|
::LEDControl.setCrgbAt(pos_, CRGB(255, 0, 0));
|
|
|
|
|
if (pos2 < LED_COUNT)
|
|
|
|
|
::LEDControl.setCrgbAt(pos2, CRGB(0, 0, 255));
|
|
|
|
|
}
|
|
|
|
|