Can someone help me combine these two scripts

Hi

I was wondering could someone help me combine these two scripts i am noob at this and not sure how to do it.I want the two rings one to spin clockwise the other other counter clockwise they work fine separate but I don’t know how to combine them.I was going to connect them to separate pins if possible instead of having them daisy chained together but if that’s not possible its fine.I am using 2 x 7-Bit WS2812 5050 RGB LED Rings.I hope i formatted the code the correct way for posting here.Please let me know if I posted in wrong section and I will delete it as this is my first post here.

first script

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

#define PIN 7
#define BRIGHTNESS 10 //  sets brightness of display

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(14, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {

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

void loop() {
 
  // Send a theater pixel chase in...

  theaterChase(strip.Color(30, 144, 255), 50); // RGB color selected in this case Blue

 

}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.setBrightness(BRIGHTNESS);  // reduces output of led per parameter set above
      strip.show();

      delay(120); //controls roation speed

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

Second Script

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

#define PIN 6
#define BRIGHTNESS 10 //  sets brightness of display

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(14, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {
  Serial.begin(9600);
  strip.begin(); strip.show(); // Initialize all pixels to 'off'
}

void loop() {

  // Send a theater pixel chase in...

  theaterChase(strip.Color(30, 144, 255), 50); // RGB color selected in this case Blue

}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
    for (int q = 0; q > -3; q--) {
      Serial.println("Turning the following LEDs on:");
      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, c);  //turn every third pixel on
        Serial.println(i + q);
      }
      strip.setBrightness(BRIGHTNESS);  // reduces output of led per parameter set above
      strip.show();

      delay(120); //controls roation speed
      Serial.println("Turning the following LEDs off:");
      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
        Serial.println(i + q);
      }
    }
  }
}

Declare two strips of type Adafruit_NeoPixel each with a different pin. Change theaterChase so that you chase on both strips one with pixel i+q and the other with pixel i-q.

Thank you for your reply I got about this far which I think is right as it verifies without any errors but I am not sure how to combine the two codes to the way you said ‘Change theater-chase so that you chase on both strips one with pixel i+q and the other with pixel i-q.’ any help would be great

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

#define PIN 6 
Adafruit_NeoPixel strip_a = Adafruit_NeoPixel(14, 6); //Define PIN 6 parameters.

#define PIN 7
    Adafruit_NeoPixel strip_b = Adafruit_NeoPixel(14, 7); //Define PIN 7 parameters.

#define BRIGHTNESS 10 //  sets brightness of display

  
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(14, PIN,NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.
void setup() {
  Serial.begin(9600);
  strip.begin(); strip.show();
  
  Adafruit_NeoPixel strip_a = Adafruit_NeoPixel(14, 6); // Initialize all pixels to 'off'
  Adafruit_NeoPixel strip_b = Adafruit_NeoPixel(14, 7); // Initialize all pixels to 'off'
}

void loop() {

  // Send a theater pixel chase in ...

theaterChase(strip.Color(30, 144, 255), 50); // RGB color selected in this case Blue

}
 //Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
    for (int q = 0; q > -3; q--) {
      Serial.println("Turning the following LEDs on:");
      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, c);  //turn every third pixel on
        Serial.println(i + q);
      }
      strip.setBrightness(BRIGHTNESS);  // reduces output of led per parameter set above
      strip.show();

      delay(120); //controls roation speed
      Serial.println("Turning the following LEDs off:");
      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
        Serial.println(i + q);
      }
    }
  }
}

I’m still at a loss with this I have gotten this far but now the code wont compile I am really new to this so not sure what I am doing wrong any help would be much appreciated.I just need the two rings to spin opposite directions.

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

#define PIN 6 
Adafruit_NeoPixel strip_a = Adafruit_NeoPixel(14, 6); //Define PIN 6 parameters.

#define PIN 7
    Adafruit_NeoPixel strip_b = Adafruit_NeoPixel(14, 7); //Define PIN 7 parameters.

#define BRIGHTNESS 10 //  sets brightness of display

  
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(14, PIN,NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  
  Serial.begin(9600);
  strip.begin(); strip.show();
  
  
}

void loop() {

  // Send a theater pixel chase in ...

theaterChase(strip.Color(30, 144, 255), 50); // RGB color selected in this case Blue

}
 //Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
    for (int q = 0; q > -3; q--) {
      Serial.println("Turning the following LEDs on:");
      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, c);  //turn every third pixel on
        Serial.println(i + q);
      }
      strip.setBrightness(BRIGHTNESS);  // reduces output of led per parameter set above
      strip.show();

      delay(120); //controls roation speed
      Serial.println("Turning the following LEDs off:");
      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
        Serial.println(i + q);
         }
 

void loop() {

  // Send a theater pixel chase in ...

theaterChase(strip.Color(30, 144, 255), 50); // RGB color selected in this case Blue

}  
// Theatre-style crawling lights.
 void theaterChase(uint32_t c, uint8_t wait){
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.setBrightness(BRIGHTNESS);  // reduces output of led per parameter set above
      strip.show();

      delay(120); //controls roation speed

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

Trash the code in #3.

Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(14, 6,NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(14, 7,NEO_GRB + NEO_KHZ800);

. . .

in setup( ), you need
strip1.begin( );
strip2.begin( );
strip1.show( );
strip2.show( );

. . .

in loop( ),

theaterChase1((strip1.Color(30, 144, 255), 50));
theaterChase2((strip2.Color(30, 144, 255), 50));

and

change theaterChase2 to be the opposite of theaterChase1

.

Thanks for your help I tried what you said but get the error “strip1 does not name a type” I am not sure how to fix that or if I did what you said correctly here is what I have

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

#define PIN 6 
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(14, 6,NEO_GRB + NEO_KHZ800);

#define PIN 7
    Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(14, 7,NEO_GRB + NEO_KHZ800);

#define BRIGHTNESS 10 //  sets brightness of display

  
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)


// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

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

void loop() {
  
  // Send a theater pixel chase in ...
}
theaterChase1((strip1.Color(30, 144, 255), 50));
}
 //Theatre-style crawling lights.
void theaterChase1(uint32_t c, uint8_t wait) {
  for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
    for (int q = 0; q > -3; q--) {
      Serial.println("Turning the following LEDs on:");
      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, c);  //turn every third pixel on
        Serial.println(i + q);
      }
      strip.setBrightness(BRIGHTNESS);  // reduces output of led per parameter set above
      strip.show();

      delay(120); //controls roation speed
      Serial.println("Turning the following LEDs off:");
      for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
        strip.setPixelColor(i + q, 0);      //turn every third pixel off
        Serial.println(i + q);
         }
 void loop() {
  
  // Send a theater pixel chase in ...
}
theaterChase2((strip1.Color(30, 144, 255), 50));
}
 //Theatre-style crawling lights.
void theaterChase2(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.setBrightness(BRIGHTNESS);  // reduces output of led per parameter set above
      strip.show();

      delay(120); //controls roation speed

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

keith889935:
Thanks for your help I tried what you said but get the error "strip1 does not name a type" I am not sure how to fix that or if I did what you said correctly here is what I have

  1. You have PIN defined twice but don't use PIN.
  2. You've got 2 loop() functions defined, you can only have one loop().
  3. You have mismatched braces.
  4. In theaterChase1 and theaterChase2 you are using the strip object which does not exist. You should use strip1 and strip2, respectively.