Referencing Multiple NeoPixel Strips

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
chucktwo
 
Posts: 2
Joined: Mon Oct 10, 2011 5:48 pm

Referencing Multiple NeoPixel Strips

Post by chucktwo »

I am working on a project where I need to run 4 neopixel strips from 4 different data pins. Is there a good way to be able to reference the different strips? For example, instead of this:

Code: Select all

     strip1.begin();
     strip1.show(); // Initialize all pixels to 'off'
     strip2.begin();
     strip2.show(); // Initialize all pixels to 'off'
     strip3.begin();
     strip3.show(); // Initialize all pixels to 'off'
     strip4.begin();
     strip4.show(); // Initialize all pixels to 'off'
I would like to use a for loop:

Code: Select all

for (int i = 0; i < Num_Strips; i++) {
strip(i).begin();
strip(i).show();
I would also like to be able to send the strip number to different functions.
I have tried several different ways (arrays, etc) and get various errors. Am I missing something easy....

User avatar
jigsawnz
 
Posts: 180
Joined: Mon Mar 12, 2012 10:17 pm

Re: Referencing Multiple NeoPixel Strips

Post by jigsawnz »

Code: Select all

#define PIN1 2
#define PIN2 3
#define PIN3 4
#define PIN4 5

Adafruit_NeoPixel strip[] = { Adafruit_NeoPixel(60, PIN1, NEO_GRB + NEO_KHZ800),
                                Adafruit_NeoPixel(60, PIN2, NEO_GRB + NEO_KHZ800),
                                Adafruit_NeoPixel(60, PIN3, NEO_GRB + NEO_KHZ800),
                                Adafruit_NeoPixel(60, PIN4, NEO_GRB + NEO_KHZ800)};

void setup() {
  // Initialise the strips
  for(uint8_t i = 0; i < sizeof(strip); i++)  {
    strip[i].begin();
    strip[i].show();  // Initialize all pixels to 'off'
  }
}
Try this.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: Referencing Multiple NeoPixel Strips

Post by adafruit_support_rick »

I don't think that sizeof(strip) will evaluate to 4. You should use (sizeof(strip)/sizeof(Adafruit_NeoPixel))
It's best to do it as a #define:

Code: Select all

#define PIN1 2
#define PIN2 3
#define PIN3 4
#define PIN4 5

Adafruit_NeoPixel strip[] = { Adafruit_NeoPixel(60, PIN1, NEO_GRB + NEO_KHZ800),
                                Adafruit_NeoPixel(60, PIN2, NEO_GRB + NEO_KHZ800),
                                Adafruit_NeoPixel(60, PIN3, NEO_GRB + NEO_KHZ800),
                                Adafruit_NeoPixel(60, PIN4, NEO_GRB + NEO_KHZ800)};
#define NUM_STRIPS (sizeof(strip)/sizeof(Adafruit_NeoPixel)) 

void setup() {
  // Initialise the strips
  for(uint8_t i = 0; i < NUM_STRIPS; i++)  {
    strip[i].begin();
    strip[i].show();  // Initialize all pixels to 'off'
  }
}

chucktwo
 
Posts: 2
Joined: Mon Oct 10, 2011 5:48 pm

Re: Referencing Multiple NeoPixel Strips

Post by chucktwo »

Thank you all so much! That was perfect!!

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”