Go Down

Topic: Define multiple strips (Read 326 times) previous topic - next topic

adrianhinge

Hello friends

The following code works, but I would like to define two or more of these strips as a single strip in order to make for example a colorwipe through multiple strips with one function call, so actually group multiple strips as being one. I have a 3D object with many strips of 24 diodes, connected to 5 different outputs on a Teensy 3.6, and would therefore like to group them when making effects.

I appreciate your help, cheers.

Code: [Select]
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define A_PIN 6
#define B_PIN 20
#define C_PIN 21
#define D_PIN 2
#define E_PIN 5

#define NUM_LEDS 24
#define BRIGHTNESS 255


Adafruit_NeoPixel strip_1 = Adafruit_NeoPixel(NUM_LEDS, A_PIN, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip_2 = Adafruit_NeoPixel(NUM_LEDS, B_PIN, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip_3 = Adafruit_NeoPixel(NUM_LEDS, C_PIN, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip_4 = Adafruit_NeoPixel(NUM_LEDS, D_PIN, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip_5 = Adafruit_NeoPixel(NUM_LEDS, E_PIN, NEO_GRBW + NEO_KHZ800);

byte neopix_gamma[] = {
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  1,  1,
    1,  1,  1,  1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  2,
    2,  3,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4,  4,  5,  5,  5,
    5,  6,  6,  6,  6,  7,  7,  7,  7,  8,  8,  8,  9,  9,  9, 10,
   10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
   17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
   25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
   37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
   51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
   69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
   90, 92, 93, 95, 96, 98, 99,101,102,104,105,107,109,110,112,114,
  115,117,119,120,122,124,126,127,129,131,133,135,137,138,140,142,
  144,146,148,150,152,154,156,158,160,162,164,167,169,171,173,175,
  177,180,182,184,186,189,191,193,196,198,200,203,205,208,210,213,
  215,218,220,223,225,228,231,233,236,239,241,244,247,249,252,255 };



void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  #if defined (__AVR_ATtiny85__)
    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  #endif
  // End of trinket special code
 
  strip_1.setBrightness(BRIGHTNESS);
  strip_1.begin();
  strip_1.show(); // Initialize all pixels to 'off'
 
  strip_2.setBrightness(BRIGHTNESS);
  strip_2.begin();
  strip_2.show(); // Initialize all pixels to 'off'
 
  strip_3.setBrightness(BRIGHTNESS);
  strip_3.begin();
  strip_3.show(); // Initialize all pixels to 'off'

  strip_4.setBrightness(BRIGHTNESS);
  strip_4.begin();
  strip_4.show(); // Initialize all pixels to 'off'
 
  strip_5.setBrightness(BRIGHTNESS);
  strip_5.begin();
  strip_5.show(); // Initialize all pixels to 'off'

}


void loop() {

  colorWipe_1(strip_1.Color(255, 0, 0, 0), 25);
  colorWipe_4(strip_1.Color(0, 255, 0, 0), 25);
  colorWipe_2(strip_1.Color(0, 0, 255, 0), 25);
  colorWipe_5(strip_1.Color(0, 0, 0, 255), 25);
  colorWipe_3(strip_1.Color(255, 255, 0, 0), 25);
 
}


// Fill the dots one after the other with a color


void colorWipe_1(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip_1.numPixels(); i++) {
    strip_1.setPixelColor(i, c);
    strip_1.show();
    delay(wait);
  }
}
void colorWipe_2(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip_2.numPixels(); i++) {
    strip_2.setPixelColor(i, c);
    strip_2.show();
    delay(wait);
  }
}
void colorWipe_3(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip_3.numPixels(); i++) {
    strip_3.setPixelColor(i, c);
    strip_3.show();
    delay(wait);
  }
}
void colorWipe_4(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip_4.numPixels(); i++) {
    strip_4.setPixelColor(i, c);
    strip_4.show();
    delay(wait);
  }
}
void colorWipe_5(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip_5.numPixels(); i++) {
    strip_5.setPixelColor(i, c);
    strip_5.show();
    delay(wait);
  }
}

Grumpy_Mike

#1
Jan 13, 2019, 10:33 pm Last Edit: Jan 13, 2019, 10:38 pm by Grumpy_Mike
Use an variable that defines the LED number you want to use, call it led.

The to get the strip to address from that
Code: [Select]
strip = led/NUM_LEDS;

To get the led number in that strip use
Code: [Select]
useLed = led%NUM_LEDS;


To make coding simpler put the strip's reference:- strip_1, strip_2 and so on into an array and use the strip variable as the index to this array.

adrianhinge

I still don't understand how to make multiple strips on individual pins of the OctoWS2811 do an effect with one call?

To make coding simpler put the strip's reference:- strip_1, strip_2 and so on into an array and use the strip variable as the index to this array.
Can you describe how you would arrange multiple pins to be one array?

Grumpy_Mike

#3
Jan 18, 2019, 12:12 am Last Edit: Jan 18, 2019, 12:13 am by Grumpy_Mike
Quote
Can you describe how you would arrange multiple pins to be one array?
Code: [Select]

// first create an instance of the libiary
Adafruit_NeoPixel strip0 = Adafruit_NeoPixel(NUMPIXELS1, PIN_FOR_STRIP1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUMPIXELS2, PIN_FOR_STRIP2, NEO_GRB + NEO_KHZ800);
// and so on

// then put each one into an array
strip[0] = strip0;
strip[1] = strip1;
// and so on

so now if you want to set an led you can use a function like this:-
Code: [Select]

void setLEDinStrip(byte whatStrip, byte whatLED, byte r, byte g, byte b){
strip[whatStrip].setPixelColor(whatLED, strip[whatStrip].Color(r,g,b));
}

adrianhinge

Hi

Code: [Select]

// first create an instance of the libiary
Adafruit_NeoPixel strip0 = Adafruit_NeoPixel(NUMPIXELS1, PIN_FOR_STRIP1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUMPIXELS2, PIN_FOR_STRIP2, NEO_GRB + NEO_KHZ800);
// and so on

// then put each one into an array
strip[0] = strip0;
strip[1] = strip1;
// and so on


I get an error when compiling stating 'strip' does not name a type?

Code: [Select]


Adafruit_NeoPixel strip_0 = Adafruit_NeoPixel(NUM_LEDS, A_PIN, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip_1 = Adafruit_NeoPixel(NUM_LEDS, B_PIN, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip_2 = Adafruit_NeoPixel(NUM_LEDS, C_PIN, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip_3 = Adafruit_NeoPixel(NUM_LEDS, D_PIN, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip_4 = Adafruit_NeoPixel(NUM_LEDS, E_PIN, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip_5 = Adafruit_NeoPixel(NUM_LEDS, F_PIN, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel strip_6 = Adafruit_NeoPixel(NUM_LEDS, G_PIN, NEO_GRBW + NEO_KHZ800);

strip[0] = strip_0;



Also will this help me define something like:

side_a = strip_0 + strip_1 + strip_2
side_b = strip_3 + strip_4 + strip_5

Which is what I'm trying to reach :)

Thank you

Best regards

Grumpy_Mike

Quote
I get an error when compiling stating 'strip' does not name a type?
Have you defined the array strip?

Quote
side_a = strip_0 + strip_1 + strip_2
side_b = strip_3 + strip_4 + strip_5

Which is what I'm trying to reach
No

Go Up