Neo Pixel - Police Lights

Hi all, I’m new to use Arduino’s so go easy on me :slight_smile:

I am trying to make two neopixel 16 pixel rings flash like police sirens for a costume.

I have found some code online which works perfectly for what I want to achieve.

The problem I have is trying to get the other neopixel ring to mirror the first neopixel ring.

I have tried defining a extra Pin hoping that it would pump the same code to both pins.

I also tried connecting the D-Out to the D-In on the neopixels hoping the signal would pass though.

But only one side will flash. I have swapped the cables over and both neopixels work fine but only one will flash so it points to the code and not the wiring.

Here is the code I’m trying to figure out:

#include <Adafruit_NeoPixel.h>

#define PIN 6
int Pixels = 16;

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

void setup()
{
  strip.begin();
  strip.show();  //Initilize strip to all off
}

void loop()
{
  delay(50);
  redFlash();  //call redFlash funtion
  delay(50);
  blueFlash();  //Call blueFlash function
}


void redFlash()
{
  for (int x=0; x<=3; x++){
  red(strip.Color(255, 0, 0), 10);  //call Red funtion - pass it color and dleay values
  red(strip.Color(0, 0, 0), 0);  //Turn off all pixels
  delay(75);
  }
}  //end redFlash

void blueFlash()
{
  for (int x=0; x<=3; x++){
  blue(strip.Color(0, 0, 255), 10);  //call blue funtion - pass it color and dleay values
  blue(strip.Color(0, 0, 0), 0);  //Turn off all pixels
  delay(75);
  }
} //end blueFlash

void red(uint32_t c, uint8_t wait)  //passed color (c) and delay (wait) values
{
  int i = 0;  //start at pixel 0
  while (i < Pixels/2)  //loop until you reach half the pixels
  {
    strip.setPixelColor(i, c);  //sets the pixel and color
    i++;
  }
  strip.show();  //turns on the pixels
  delay(wait);  //wait designated time (wait)
}  //end red

void blue(uint32_t c, uint8_t wait)  //passed color (c) and delay (wait) values
{
  int i = Pixels+1;  //start at the last pixel
  while (i > Pixels/2-1)  //loop until you reach half the pixels
  {
    strip.setPixelColor(i, c);  //sets pixel and color  
    i--;
  }
  strip.show();  //turns on pixels
  delay(wait);  //wait designated time (wait)  
}  //end blue

I’m hoping this is something simple to correct?

Many Thanks in advance guys!

:slight_smile:

LukaUK:
Hi all, I’m new to use Arduino’s so go easy on me :slight_smile:

An opening sure to get you lots of extra hard time.

LukaUK:
I am trying to make two neopixel 16 pixel rings flash like police sirens for a costume.

Sirens make noise. They don’t flash. You might need to rethink this idea.

LukaUK:
I have found some code online which works perfectly for what I want to achieve.

Great! Use it if it is exactly what you want. If not then you’re going to have to do some learning to make it change.

LukaUK:
The problem I have is trying to get the other neopixel ring to mirror the first neopixel ring.

Hold a mirror up to it?

LukaUK:
I have tried defining a extra Pin hoping that it would pump the same code to both pins.

Electronics and programming don’t run on hope. Have you learned anything about how neopixels work? They’re addressable. That’s important.

LukaUK:
I also tried connecting the D-Out to the D-In on the neopixels hoping the signal would pass though.

The signal does pass through. But it is only talking to the lights at certain addresses. You need to write code to send something to the other lights.

LukaUK:
But only one side will flash. I have swapped the cables over and both neopixels work fine but only one will flash so it points to the code and not the wiring.

That is does indeed.

LukaUK:
Here is the code I’m trying to figure out:

#include <Adafruit_NeoPixel.h>

#define PIN 6
int Pixels = 16;

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

void setup()
{
  strip.begin();
  strip.show();  //Initilize strip to all off
}

void loop()
{
  delay(50);
  redFlash();  //call redFlash funtion
  delay(50);
  blueFlash();  //Call blueFlash function
}

void redFlash()
{
  for (int x=0; x<=3; x++){
  red(strip.Color(255, 0, 0), 10);  //call Red funtion - pass it color and dleay values
  red(strip.Color(0, 0, 0), 0);  //Turn off all pixels
  delay(75);
  }
}  //end redFlash

void blueFlash()
{
  for (int x=0; x<=3; x++){
  blue(strip.Color(0, 0, 255), 10);  //call blue funtion - pass it color and dleay values
  blue(strip.Color(0, 0, 0), 0);  //Turn off all pixels
  delay(75);
  }
} //end blueFlash

void red(uint32_t c, uint8_t wait)  //passed color (c) and delay (wait) values
{
  int i = 0;  //start at pixel 0
  while (i < Pixels/2)  //loop until you reach half the pixels
  {
    strip.setPixelColor(i, c);  //sets the pixel and color
    i++;
  }
  strip.show();  //turns on the pixels
  delay(wait);  //wait designated time (wait)
}  //end red

void blue(uint32_t c, uint8_t wait)  //passed color (c) and delay (wait) values
{
  int i = Pixels+1;  //start at the last pixel
  while (i > Pixels/2-1)  //loop until you reach half the pixels
  {
    strip.setPixelColor(i, c);  //sets pixel and color 
    i–;
  }
  strip.show();  //turns on pixels
  delay(wait);  //wait designated time (wait) 
}  //end blue




I'm hoping this is something simple to correct?

Many Thanks in advance guys!

:)

Look at the top of your code. Can you figure out which line is telling it how many lights you have? If not, then look at tutorials and docs on the library. How many lights are you trying to have? How many lights does this code say it is for? It looks like a pretty trivial change to make it apply to more lights. But you’ll have to at least do a little cursory looking at the docs for the library.

Look at this... Maybe you'll find something helpful.
[AD]https://forum.arduino.cc/index.php?topic=554916.0[/AD]

On the picture, the short black wire connects the GND of both rings, the red wire connects VIN or VCC, and the green wire connects the Dout of the first ring to the Din of the second.

Delta_G:
Look at the top of your code. Can you figure out which line is telling it how many lights you have? If not, then look at tutorials and docs on the library. How many lights are you trying to have? How many lights does this code say it is for? It looks like a pretty trivial change to make it apply to more lights. But you'll have to at least do a little cursory looking at the docs for the library.

Thank you for pointing that bit out for me, I changed int Pixels = 16; to int Pixels = 32; and it works perfectly!

Thank you very much for you help guys! Much Appreciated!

you can also connect the single data line to both rings DIN, then it will drive them both identically and depending on how you position them relative to each other you will get a perfect mirroring with no code alterations.

not sure how many different lines you can run like this, but a single data-line will drive two strips (or rings) just fine.