FastLed WS2812b layered effects. Possible?

I'm using an Arduino Nano running a WS2811B strip with 59 leds oriented in a circle from end to end mounted under the top housing of the speaker. The leds you see in the video are actually reflections of the top mounted leds. The pic shows the leds mounted on the bottom of the top cover. The box is a down firing sealed box with a plexiglass viewport on top showing the back of the shallow mount woofer.

"it will write to array positions with a negative index?" So it won't stop even though the condition is "whiteLed > 0?" Where is the negative coming from?

In yours code 'int whiteLed' is from 59 to 0 and if whiteLed = 0 for T1 = whiteLed - 1 (=-1), T2 = whiteLed - 2 (=-2) and so on. Those 4 variables (T) are negative index in array.

Congrats for yours progress.

1 Like

"In yours code 'int whiteLed' is from 59 to 0 and if whiteLed = 0 for T1 = whiteLed - 1 (=-1), T2 = whiteLed - 2 (=-2) and so on. " Off course, thanks for pointing that out. One of the issues is that hadn't taken the direction of the WS2812 into account when I mounted it to the lid. Looking at it from the top down as in the video, the strip starts at the 6 o'clock position and follows the perimeter for 360 degrees until it end back at 6 o'clock. The problem is that it starts at the strips end, led 59, and ends at the leds starting led, 0. Looking at it from the bottom, I hadn't taken into account that the lid will be flipped, in essence a mirror image of how I mounted them. Instead of re-mounting them in the correct orientation, I thought I'd just tweak the code, and that should be possible, but a bit more convoluted than if they were oriented correctly to begin with.

So in that piece of code, the led is moving clockwise, but it has to be written backwards as the head is moving towards zero. I'll change it so I won't have negative numbers in the array.

R

If I change one value in that code, it should be ok - change

"whiteLed > 0;" to

"whiteLed > 4;"

I did that and ran the code but there is a repercussion when the comet crosses right to left over the 6 o'clock position where the ends meet. No problem, I'll iron that out.

// Yours code.
for ( int whiteLed = 59; whiteLed > 0; whiteLed = whiteLed - 1 ) // only 59 leds from all 60
  // for all 60 leds whiteLed > 0 must be whiteLed >= 0
{
  leds [ whiteLed ] = CRGB::OrangeRed;
  T1 = whiteLed - 1;
  T2 = whiteLed - 2;
  T3 = whiteLed - 3;
  T4 = whiteLed - 4;
  leds [ T1 ] = CRGB::Orange;
  leds [ T2 ] = CRGB::OrangeRed;
  leds [ T3 ] = CRGB::Red;
  leds [ T4 ] = CRGB::Red;
  FastLED.show ();
  delay ( 15 );
}

// Modification for negative array index (dropping).
for ( int whiteLed = 59; whiteLed >= 0; whiteLed -- )
{
  leds [ whiteLed ] = CRGB::OrangeRed;
  T1 = whiteLed - 1;
  T2 = whiteLed - 2;
  T3 = whiteLed - 3;
  T4 = whiteLed - 4;
  if ( T1 >= 0 ) leds [ T1 ] = CRGB::Orange;
  if ( T2 >= 0 ) leds [ T2 ] = CRGB::Orange;
  if ( T3 >= 0 ) leds [ T3 ] = CRGB::Orange;
  if ( T4 >= 0 ) leds [ T4 ] = CRGB::Orange;
  FastLED.show ();
  delay ( 15 );
}

// Modification for negative array index (cyclic).
for ( int whiteLed = 59; whiteLed >= 0; whiteLed -- )
{
  leds [ whiteLed ] = CRGB::OrangeRed;
  T1 = whiteLed - 1;
  T2 = whiteLed - 2;
  T3 = whiteLed - 3;
  T4 = whiteLed - 4;
  if ( T1 < 0 ) T1 += 60;
  if ( T2 < 0 ) T2 += 60;
  if ( T3 < 0 ) T3 += 60;
  if ( T4 < 0 ) T4 += 60;
  leds [ T1 ] = CRGB::Orange;
  leds [ T2 ] = CRGB::OrangeRed;
  leds [ T3 ] = CRGB::Red;
  leds [ T4 ] = CRGB::Red;
  FastLED.show ();
  delay ( 15 );
}

// Modification for negative array index (cyclic and mirror).
for ( int whiteLed = 59; whiteLed >= 0; whiteLed -- )
{
  leds [ 59 - whiteLed ] = CRGB::OrangeRed;
  T1 = 59 - whiteLed + 1;
  T2 = 59 - whiteLed + 2;
  T3 = 59 - whiteLed + 3;
  T4 = 59 - whiteLed + 4;
  if ( T1 > 59 ) T1 -= 60;
  if ( T2 > 59 ) T2 -= 60;
  if ( T3 > 59 ) T3 -= 60;
  if ( T4 > 59 ) T4 -= 60;
  leds [ T1 ] = CRGB::Orange;
  leds [ T2 ] = CRGB::OrangeRed;
  leds [ T3 ] = CRGB::Red;
  leds [ T4 ] = CRGB::Red;
  FastLED.show ();
  delay ( 15 );
}

// Modification for negative array index (cyclic and different start/end).
int SE = 15, n; // start/end 15 led
for ( int whiteLed = 59; whiteLed >= 0; whiteLed -- )
{
  n = whiteLed - SE;
  if ( n < 0 ) leds [ n + 60 ] = CRGB::OrangeRed; else leds [ n ] = CRGB::OrangeRed;
  T1 = n - 1;
  T2 = n - 2;
  T3 = n - 3;
  T4 = n - 4;
  if ( T1 < 0 ) T1 += 60;
  if ( T2 < 0 ) T2 += 60;
  if ( T3 < 0 ) T3 += 60;
  if ( T4 < 0 ) T4 += 60;
  leds [ T1 ] = CRGB::Orange;
  leds [ T2 ] = CRGB::OrangeRed;
  leds [ T3 ] = CRGB::Red;
  leds [ T4 ] = CRGB::Red;
  FastLED.show ();
  delay ( 15 );
}

Maybe with little help from math. My code is just suggestion and not tested.

1 Like

My head is spinning with everything I've been reading and trying to understand. Let me take a shot at your suggestions.

I ran the first suggestion and it worked. The colors were obviously orange, but it worked.

The second one worked and had the necessary colors.

The third visually gave the same results as the second, even though from the description I was expecting it to mirror the results after one iteration.

The third code snippet gave me an error:

exit status 1
expected unqualified-id before numeric constant

I've googled int and arduino but came up short in trying to find out what the error meant nor how to correct it. My guess is that "n" hasn't been declared?

No, just reversing (if workings as I wanted).

Fourth code maybe? Probably int SE = 15, n; is reason for that error. Try to remove int SE = 15, n; and changes n = whiteLed - SE; to int n = whiteLed - 15;. Or try different idea.

Yes, I meant reversing when I said mirror, but it didn't do that.

And yes, fourth code error was the SE = 15, n;

I'll try your recommended changes and am also working on another way to tackle the problem.

Funny how I got sidetracked with the comet routine, but the two routines have to work properly before combining them.