Groups of Neopixels

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
User avatar
benberfield
 
Posts: 6
Joined: Tue Aug 26, 2014 2:37 pm

Groups of Neopixels

Post by benberfield »

I have been looking for a while trying to figure out how I can assign specific pixels on a strip of Neopixels, to groups of 3-5 and then have those groups randomly flash. I haven't been able to find any examples where the group sizes vary.

Any help is appreciated.

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

Re: Groups of Neopixels

Post by adafruit_support_rick »

Sounds like you want to create an array of groups, where each group is a list of pixels. Something like this:

Code: Select all

//groups of pixels are lists terminated by -1
int group0[] =  {0, 1, 2, -1};
int group1[] =  {3, 4, 5, 6, -1};
int group2[] =  {7, 8, 9, 10, 11, -1};
int group3[] =  {12, 13, 14, -1};

//Declare an array of groups
int* groups[] = {
                  group0,
                  group1,
                  group2,
                  group3
                };

//Compute the number of groups         
#define NUM_GROUPS (sizeof(groups) / sizeof(int*))

void setup()
{
  while (!Serial);
  Serial.begin(9600);
}

void loop()
{
  for (int groupNum=0; groupNum < NUM_GROUPS; groupNum++)    //for each group
  {
    int* groupList = groups[groupNum];        //get a pointer to the current list
    
    while (*groupList != -1)              //for each pixel in the list
    {
      Serial.print(*groupList); Serial.print(", ");  //print the pixel number
      groupList++;                      // increment to point to the next pixel
    }
    
    Serial.println();
  }
  delay(5000);
}
So, you define a list of pixel numbers for each group you want. Terminate the list with -1; that way you can have variable length lists. Then define an array of pointers to those lists.
In your code, you loop through the list until you get to a -1. The example just prints out the pixel number, but you can do anything you want.

User avatar
benberfield
 
Posts: 6
Joined: Tue Aug 26, 2014 2:37 pm

Re: Groups of Neopixels

Post by benberfield »

This works great! I was heading in this direction but I did not think about terminating with -1.

Thanks again

User avatar
benberfield
 
Posts: 6
Joined: Tue Aug 26, 2014 2:37 pm

Re: Groups of Neopixels

Post by benberfield »

Any way you could show me how to add that group to the color wipe effect? Or even just how to change the first section to blue? I think I should be able to get it from there.

Code: Select all

void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, c);
      strip.show();
      delay(wait);
  }

Thanks again!

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

Re: Groups of Neopixels

Post by adafruit_support_rick »

Something like this?

Code: Select all

for (int groupNum=0; groupNum < NUM_GROUPS; groupNum++)    //for each group
  {
    colorWipe(groups[groupNum], strip.color(0, 0, 255), 50);
  }
  
void colorWipe(int* groupList, uint32_t c, uint8_t wait) {
  while (*groupList != -1) {            //for each pixel in the list
      strip.setPixelColor(*groupList, c);    //set the pixel color
      groupList++;          // increment to point to the next pixel
      strip.show();
      delay(wait);
  }
}

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

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