FastLED: mirroring data to another pin

Hi all
I want to duplicate data from one pin to another pin. duplication works fine with this code.

line1 [pixel ] = CHSV(beatA, 0, 255); 
line2 [pixel ] = CHSV(beatA, 0, 255); 
line3 [pixel ] = CHSV(beatA, 0, 255); 
LEDS.show(); 
line1 [pixel ] = CHSV(beatA, 255, 255); 
line2 [pixel ] = CHSV(beatA, 255, 255); 
line3 [pixel ] = CHSV(beatA, 255, 255); 

but to make it simpler and I tried with this code, but it doesn't work.

line1 [pixel ] = line2 [pixel ] = line3 [pixel ] ;

how to simply duplicate data to another pin. Thank You.

#include <FastLED.h>

#define NUM_LEDS 32
#define BRIGHTNESS 200

CRGB line1[NUM_LEDS];
CRGB line4[NUM_LEDS];
CRGB line2[NUM_LEDS];
CRGB line3[NUM_LEDS];

#define outLine1   2 //strip output
#define outLine4 13
#define outLine2 12 //strip output
#define outLine3 11

void setup() {
  delay(1000);
  FastLED.addLeds<WS2812B, outLine1, GRB>(line1, NUM_LEDS);
  FastLED.addLeds<WS2812B, outLine4, GRB>(line4, NUM_LEDS);
  FastLED.addLeds<WS2812B, outLine2, GRB>(line2, NUM_LEDS);
  FastLED.addLeds<WS2812B, outLine3, GRB>(line3, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
}

void loop() {

pattern1();
LEDS.show();
}

int pixel = 0;
void pattern1() {

  fadeToBlackBy( line1, NUM_LEDS, 10);
  uint8_t beatA = beatsin8(80, 5, 255);

  line1 [pixel ] = CHSV(beatA, 0, 255); //CHSV(random8(), 255, 255);
  LEDS.show();
  line1 [pixel ] = CHSV(beatA, 255, 255); //CHSV(random8(), 255, 255);

  EVERY_N_MILLISECONDS(20) {

    pixel++;
    if ( pixel >= NUM_LEDS ) {
      pixel = 0;
    }
  }
  line1 [pixel ] = line2 [pixel ] = line3 [pixel ] = line4 [pixel ] ;
}

You don't set anything to something.

line1[pixel] = line2[pixel] = line3[pixel] = CHSV(beatA, 0, 255); 

HTH

a7

why mirroring? connect them together

1 Like

only line2 displays the code, the others are only white

i need another pin to make animation

line4[pixel] has not been set to anything, so it will be zero/black. This code sets the other 3 to black also.

Perhaps you meant

line4 [pixel ] = line3 [pixel ] = line2 [pixel ] = line1 [pixel ] ;

you can only copy stored array, one to another, because the pin while sending the data in the strip is controlled by assembler code

I assume that with this code, line2,3,4 will light up following line1.

Sorry, I am wrong. after deleting the code below and moving it to the top. apparently it worked.

void pattern1() {

  fadeToBlackBy( line1, NUM_LEDS, 10);
  fadeToBlackBy( line2, NUM_LEDS, 10);
  fadeToBlackBy( line3, NUM_LEDS, 10);
  fadeToBlackBy( line4, NUM_LEDS, 10);

  uint8_t beatA = beatsin8(80, 5, 255);

  line1[pixel] = line2[pixel] = line3[pixel] = line4[pixel] = CHSV(beatA, 0, 255);
  LEDS.show();
  line1[pixel] = line2[pixel] = line3[pixel] = line4[pixel] = CHSV(beatA, 255, 255);

  EVERY_N_MILLISECONDS(20) {

    pixel++;
    if ( pixel >= NUM_LEDS ) {
      pixel = 0;
    }
  }
}

Thank you

Don't settle for apparently! It worked because you wrote it correctly.

You are poking around the areas known as operator precedence and associativity.

Your mistake was thinking that the first thing would go into making the second thing, then the third left to right. As you see now, that is backwards to what happens. The assignment operator associates such that the first assignment performed is the last one, the on the right. Then the result of that assignment, that is to say the value assigned, is used in the next one over to the left. And so on, so all the linex[ ] things end up being the same CHSV(beatA, 0, 255).

This article will say everything, and say it better than I could:

You can always know what is going to happen when you write an expression in C/C++. You can always know when adding parentheses or re-arranging things is necessary. You may find yourself looking at the precedence chart even after N years of programming.

HTH

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.