Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!




Help on Code for Mu...
 
Share:
Notifications
Clear all

Help on Code for Multi-Array (2 strips with different LED count)

4 Posts
2 Users
0 Likes
2,049 Views
 zef
(@zef)
New Member
Joined: 3 years ago
Posts: 2
Topic starter  

Hi everyone, this is my first post although I've already received a lot of help through article comments which I am grateful for.

I don't have any experience in ws2812b projects using Uno, especially coding. I am doing my best to read/watch stuff about it online. So far, Tweaking4all has been my guide to start my project. From the materials needed up to making it work, this has helped me a lot. Now I'm on the part where I want to add a code for it. I tried to compile 2 existing codes for my project, The first part of the code was from arduino forums and the second one was from Hans (Meteor Rain). Although I really want a combination of Cyclon and Ranbow March, I think it may be advanced for me so I am doing a single effect for the 2 strips for now.

What I am using:

Arduino Uno & WS2812b (2 Strips / 30leds and 121leds)

I am getting this error message: expected unqualified-id before numeric constant  from the 2nd line:

#define NUM_LEDS_PER_STRIP_A 121
#define NUM_LEDS_PER_STRIP_B 30

I know more errors will come after this one. I just want to know what caused this issue to happen.

 

The entirety of the code that I was trying to compile:

// MultipleStripsInOneArray - see  https://github.com/FastLED/FastLED/wiki/Multiple-Controller-Examples  for more info on
// using multiple controllers.  In this example, we're going to set up four NEOPIXEL strips on three
// different pins, each strip will be referring to a different part of the single led array

#include <FastLED.h>
 
 #define NUM_LEDS_PER_STRIP_A 121
 #define NUM_LEDS_PER_STRIP_B 30

#define NUM_LEDS 151

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds<WS2812B, 6>(leds, 121, NUM_LEDS_PER_STRIP_A);

  FastLED.addLeds<WS2812B, 5>(leds, 30, NUM_LEDS_PER_STRIP_B);

int NUM_LEDS_PER_STRIP_A = 0;
int NUM_LEDS_PER_STRIP_B = 0;
}

void loop() {

  meteorRain(0xff, 0xff, 0xff, 10, 64, true, 30);
}
 
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  if (Strip1Position==0) { fill_solid( leds1, NUM_LEDS_PER_STRIP_A, CRGB(0,0,0)); }
  if (Strip2Position==0) { fill_solid( leds2, NUM_LEDS_PER_STRIP_B, CRGB(0,0,0)); }
 
  
  // fade brightness all LEDs one step
  for(int j=0; j<NUM_LEDS_PER_STRIP_A; j++) {
    if( (!meteorRandomDecay) || (random(10)>5) ) {
      leds1[j].fadeToBlackBy(meteorTrailDecay); 
    }
  }
  
  for(int j=0; j<NUM_LEDS_PER_STRIP_B; j++) {
    if( (!meteorRandomDecay) || (random(10)>5) ) {
      leds2[j].fadeToBlackBy(meteorTrailDecay); 
    }
  }
  
   
  // draw meteor
  for(int j = 0; j < meteorSize; j++) {
    if( ( i-j <NUM_LEDS_PER_STRIP_A) && (i-j>=0) ) {
      leds1[i-j] = CRGB(red, green, blue);
    }
  }
   
  for(int j = 0; j < meteorSize; j++) {
    if( ( i-j <NUM_LEDS_PER_STRIP_B) && (i-j>=0) ) {
      leds2[i-j] = CRGB(red, green, blue);
    }
  }

  
  FastLED.show();
  delay(SpeedDelay);
  
  if(NUM_LEDS_PER_STRIP_APosition<NUM_LEDS_PER_STRIP_A+NUM_LEDS_PER_STRIP_A) {
    Strip1Position++; 
  }
  else
  {
    Strip1Postion = 0;
  }
  
  if(NUM_LEDS_PER_STRIP_BPosition<NUM_LEDS_PER_STRIP_B+NUM_LEDS_PER_STRIP_B) {
    Strip2Position++; 
  }
  else
  {
    Strip2Position = 0;
  }
  
 
}
}

}

   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2654
 

Hi Zef!

Welcome to the forum!

When looking at your code, I see a few things that may not be entirely correct (partially my fault maybe).
I've corrected a few things, and hopefully this helps you get to the next step 😊 

// MultipleStripsInOneArray - see   https://github.com/FastLED/FastLED/wiki/Multiple-Controller-Examples   for more info on
// using multiple controllers.  In this example, we're going to set up four NEOPIXEL strips on three
// different pins, each strip will be referring to a different part of the single led array

#define FASTLED_INTERNAL // just used to mute the Pragma messages when compiling
#include <FastLED.h>

#define NUM_LEDS_STRIP_A 121
#define NUM_LEDS_STRIP_B 30

#define PIN_STRIPA 6
#define PIN_STRIPB 5

#define NUM_LEDS 151

CRGB leds1[NUM_LEDS_STRIP_A];
CRGB leds2[NUM_LEDS_STRIP_B];

int Strip1Position = 0;
int Strip2Position = 0;

void setup() {
  FastLED.addLeds<WS2812B, PIN_STRIPA, GRB>(leds1, NUM_LEDS_STRIP_A).setCorrection( TypicalLEDStrip );
  FastLED.addLeds<WS2812B, PIN_STRIPB, GRB>(leds2, NUM_LEDS_STRIP_B).setCorrection( TypicalLEDStrip );
}

void loop() {

  meteorRain(0xff, 0xff, 0xff, 10, 64, true, 30);
}

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
  if (Strip1Position == 0) {
    fill_solid(leds1, NUM_LEDS_STRIP_A, CRGB(0, 0, 0));
  }
  if (Strip2Position == 0) {
    fill_solid(leds2, NUM_LEDS_STRIP_B, CRGB(0, 0, 0));
  }

  // fade brightness all LEDs one step
  for (int j = 0; j < NUM_LEDS_STRIP_A; j++) {
    if ((!meteorRandomDecay) || (random(10) > 5)) {
      leds1[j].fadeToBlackBy(meteorTrailDecay);
    }
  }

  for (int j = 0; j < NUM_LEDS_STRIP_B; j++) {
    if ((!meteorRandomDecay) || (random(10) > 5)) {
      leds2[j].fadeToBlackBy(meteorTrailDecay);
    }
  }

  // draw meteor
  for (int j = 0; j < meteorSize; j++) {
    if ((Strip1Position - j < NUM_LEDS_STRIP_A) && (Strip1Position - j >= 0)) {
      leds1[Strip1Position - j] = CRGB(red, green, blue);
    }
  }

  for (int j = 0; j < meteorSize; j++) {
    if ((Strip2Position - j < NUM_LEDS_STRIP_B) && (Strip2Position - j >= 0)) {
      leds2[Strip2Position - j] = CRGB(red, green, blue);
    }
  }

  FastLED.show();
  delay(SpeedDelay);

  if (Strip1Position < NUM_LEDS_STRIP_A + NUM_LEDS_STRIP_A) {
    Strip1Position++;
  } else {
    Strip1Position = 0;
  }

  if (Strip2Position < NUM_LEDS_STRIP_B + NUM_LEDS_STRIP_B) {
    Strip2Position++;
  } else {
    Strip2Position = 0;
  }

}

   
ReplyQuote
 zef
(@zef)
New Member
Joined: 3 years ago
Posts: 2
Topic starter  

@hans

Wow, it works! Thank you so much Hans! Now I'm going to figure out how to replace the effects with other existing ones out there. Specially the Cyan or Rainbow March. 😀 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2654
 

Excellent! 😊 


   
ReplyQuote

Like what you see and you'd like to help out? 

The best way to help is of course by assisting others with their questions here in the forum, but you can also help us out in other ways:

- Do your shopping at Amazon, it will not cost you anything extra but may generate a small commission for us,
- send a cup of coffee through PayPal ($5, $10, $20, or custom amount),
- become a Patreon,
- donate BitCoin (BTC), or BitCoinCash (BCH).

Share: