Neopixel LED string: Can't get a second string to light up

Hi. We are grade 5 students from Toronto. We have successfully lit up a single Adafruit Neopixel programmable LED strip. However, we are having trouble lighting up a second string. We want the first string to light up, then go off, and then have the second string light up and go off. Here is what we have working for the one string, followed by our code for the two strings. Any help is appreciated!!

One String:

#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h>
#endif

#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

strip.begin();
strip.show(); // Initialize all pixels to ‘off’
}

void loop() {
// Some example procedures showing how to display to the pixels:
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue

}

// Fill the dots one after the other with a color
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);
}
}

Here is our modified code. There are no error messages, but it does not work. We are not sure exactly what the latter part of the code does, so that is probably where our error is.

#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h>
#endif

#define PIN 6
Adafruit_NeoPixel strip_a = Adafruit_NeoPixel(60, 6, NEO_GRB + NEO_KHZ800); //pin 6 will run strip_a
#define PIN 7
Adafruit_NeoPixel strip_b = Adafruit_NeoPixel(60, 7, NEO_GRB + NEO_KHZ800); //pin 7 will run strip_b

void setup() {

strip_a.begin();
strip_a.show(); // Initialize all pixels to ‘off’

strip_b.begin();
strip_b.show(); // Initialize all pixels to ‘off’
}

void loop() {
colorWipe(strip_a.Color(255, 0, 0), 50); // Red for pin 6
colorWipe(strip_a.Color(0, 0, 0), 50); // Black for pin 6
delay(1000);
colorWipe(strip_b.Color(0, 255, 0), 50); // Green for pin 7
colorWipe(strip_b.Color(0, 0, 0), 50); // Black for pin 7
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip_a.numPixels(); i++) {
strip_a.setPixelColor(i, c);
strip_a.show();
delay(10);
}
{
for(uint16_t i=0; i<strip_b.numPixels(); i++) {
strip_b.setPixelColor(i, c);
strip_b.show();
delay(10);
}
}
}

It looks like in colorWipe(), you are writing to both strips every time you call it?

When you have code that compiles but doesn’t work, you should always describe what it does when asking for help, because that gives a clue as to what’s wrong.

When you post code, you should put it in code tags (highlight it and click the </> button ) so it is easier to read.

{
  for(uint16_t i=0; i<strip_b.numPixels(); i++) {
    strip_b.setPixelColor(i, c);
    strip_b.show();
    delay(10);
  }
}

What are the outer curly braces for?

If you put every { on a new line, where it belongs, and used Tools + Auto Format, you’d see that the outer curly braces in that snippet are useless.

I’m not sure why your second program did not work, but I slightly rewrote your first one and it seems to work. I only have a single 8 pixel NeoPixel stick to test with.

My changes:

  • define two constants for strip a and b pins (I only used pin 6, you’ll have to change one to 7)
  • define a constant for the number of pixels (8 for me, you’ll have to change it to 60)
  • define a pointer to a strip object
  • rework colorWipe() to take a strip pointer as a parameter

The last change simplifies the code. First pass colorWipe() a pointer to strip a, then pass it a pointer to strip b. I recommend for the sake of testing to try running the code with both pin constants set to 6, then with both set to 7. If they light up as expected then set STRIP_A_PIN to 6 and STRIP_B_PIN to 7.

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define STRIP_A_PIN 6  // strip a pin
#define STRIP_B_PIN 6  // strip b pin

#define PIXEL_COUNT 8  // # of pixels

Adafruit_NeoPixel strip_a = Adafruit_NeoPixel(PIXEL_COUNT, STRIP_A_PIN, NEO_GRB + NEO_KHZ800);

Adafruit_NeoPixel strip_b = Adafruit_NeoPixel(PIXEL_COUNT, STRIP_B_PIN, NEO_GRB + NEO_KHZ800);

Adafruit_NeoPixel *strip;  // points to strip a or strip b

void setup() {
  Serial.begin(9600);


  strip_a.begin();
  strip_a.show(); // Initialize all pixels to 'off'


  strip_b.begin();
  strip_b.show(); // Initialize all pixels to 'off'

}



void loop() {

  // use strip a
  strip = &strip_a;

  // Some example procedures showing how to display to the pixels:
  colorWipe(strip,strip->Color(255, 0, 0), 50); // Red
  colorWipe(strip,strip->Color(0, 0, 0), 50); // Black

  // use strip b
  strip = &strip_b;

  colorWipe(strip,strip->Color(0, 255, 0), 50); // Green
  colorWipe(strip,strip->Color(0, 0, 0), 50); // Black
}

// Fill the dots one after the other with a color
void colorWipe(Adafruit_NeoPixel *s, uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<s->numPixels(); i++) {
    s->setPixelColor(i, c);
    s->show();
    delay(wait);
  }
}