Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Multiple LED strips...
 
Share:
Notifications
Clear all

[Solved] Multiple LED strips on Mulitple pins

14 Posts
2 Users
0 Reactions
3,097 Views
(@mr_ben)
Active Member
Joined: 9 years ago
Posts: 7
Topic starter  

Hello Hans,

Like many others I am insanely grateful for your rich and articulate website on Arduino, especially the LED strip library.

I am not a programmer, but have been dabbling with LEDs for several different projects and this is my first time using programmable LED strips. I would like to use your code for the sparkle effect on multiple different strips, turning one on, then off, then activating another strip. Is it possible to do this while also changing some of the parameters of the sparkle effect on each strip? 

I have been able to engage two pins and make them both either on or off, but I think I am coming at it from the wrong direction. Obviously this could be too much to ask, any pointers would be great!

The code :  (is your code)

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 27
// Parameter 1 = number of pixels in strip
// Parameter 2 = 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)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

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

// REPLACE FROM HERE
void loop() {
  Sparkle(0xff, 0xff, 0xff, 0);
}

void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}
// REPLACE TO HERE

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2860
 

Hello Mr_Ben,

first of all, thank you very much for the kind compliment! Always a good motivator to keep working on my website (I honestly wish I could make this my day-time job). 

As for your project;

If I understand you correctly, you want multiple strips, however a sparkle should only appear on one strip, then removed, and then a sparkle on another strip should appear. In my head, I'm not quite sure what the end result should look like. But that doesn't need to be an issue.

The easiest way would be by using 1 single strip, just cutting it in pieces, and reconnecting them, just so we can "stack" the strips (see attached image - pretty bad drawing on my end, but I hope you get the idea).

Now, let's say each strip is 10 LEDs, and we have for example 4 strips.

The first option is just the code as is, LEDs will randomly light up on any position in this "square".

We could also force it to pick particular "rows" - this comes down to me not quite knowing what you have in mind.

...
#define LEDS_PER_STRIP 10
...
void loop() {
  Sparkle(0, 0xff, 0xff, 0xff, 0); // first strip
  Sparkle(1, 0xff, 0xff, 0xff, 0); // second strip
  Sparkle(2, 0xff, 0xff, 0xff, 0); // third strip
  Sparkle(3, 0xff, 0xff, 0xff, 0); // fourth strip
}
void Sparkle(byte strip, byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(LEDS_PER_STRIP); // pick a random value 0...10
  Pixel = Pixel + (strip * LEDS_PER_STRIP); // shift the position so we get the right strip
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

This is just a crude example. There are more elegant ways to do this, and I'm not sure if this is what you had in mind ...
It will set a random LED ON and OFF again, one strip at a time, starting with the first strip, all the way to the last strip, and then start over again.

Is this what you had in mind?


   
ReplyQuote
(@mr_ben)
Active Member
Joined: 9 years ago
Posts: 7
Topic starter  

Hans!

What a resource, I am very grateful, none of my friends or colleagues deal with electronics so I am swimming solo here in LA.

First I should apologize, my description of the effect I wanted was not so clear. So I have included a diagram .

Most importantly I would like to have one sequence which engages the sparkle effect on the LED's of the first strip for thirty seconds then turns them off for thirty seconds: the turns the sparkle effect on for strip two for thirty seconds, then turns off for thirty seconds:  then on strip three,,,, and so on.  I understand that you already have each individual LED going from one strand to the next, but I would like to engage all the LED's for the sparkle effect on a single strip then turn it off.  

Sorry if this is unclear, I am new to this and although it is simple, I now understand writing it is far more demanding : )

Very very grateful for your time and interest in this little project ,

B


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2860
 

Hi Mr_Ben,

no problem, describing what one is looking for can be tricky indeed .

Is there a specific reason why it must be 4 separate strands?
Where I'm going with this is that controlling one single strand is much easier, and in code we can define which section of a strand is which "strip". This way we can say:

- Sparkle LEDs 1-10 for 30 seconds.
- LEDs 1-10 off for 30 seconds. 

- Sparkle LEDs 11-20 for 30 seconds.
- LEDs 12-20 off for 30 seconds. 

etc.

LED strips can be cut, simply with scissors on the spot where it shows 3 copper "pads", and the only thing one needs to do is to make sure +5V, GND and Din, of the 2nd strip are reconnected with wires to the end of the first strip, and so on.

Connecting 4 strands, each on its own pin, might cause issues with defining or defining multiple:

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

So this could be something like this:

...
#define PIN1 6
#define PIN2 7
#define PIN3 8
#define PIN4 9 ...
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUM_LEDS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUM_LEDS, PIN2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(NUM_LEDS, PIN3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(NUM_LEDS, PIN4, NEO_GRB + NEO_KHZ800);
...

The potential problem with that would be that it takes much more memory, and the memory of your Arduino is limited.
I have not tested this though, and the pin numbers are random, I don't know from the top of my head of 7, 8 and 9 can be used for this.

One thing I'm unclear about is this:
Once the first strand has been off for 30 seconds, and strip 2 is started, should strand 1 start again as well?

Meaning: 

Strip 1 30 seconds sparkle. All dark for 30 seconds.
Strips 1 and 2 sparkle for 30 seconds. All dark for 30 seconds.
Strips 1, 2 and 3 sparkle for 30 seconds. All dark for 30 seconds.
Strips 1, 2, 3 and 4 sparkle for 30 seconds. All dark for 30 seconds.

Or did you mean:

Strip 1 30 sec. sparkle. All dark for 30 seconds.
Strip 2 30 sec. sparkle. All dark for 30 seconds.
Strip 3 30 sec. sparkle. All dark for 30 seconds.
Strip 4 30 sec. sparkle. All dark for 30 seconds.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2860
 

For timing 30 seconds, I found something (modified it) that might help (source):

// 1 second = 1000 milliseconds
#define STRIP1_START 0
#define STRIP1_STOP 30000
#define STRIP2_START 60000
#define STRIP2_STOP 90000
#define STRIP3_START 120000
#define STRIP3_STOP 150000
#define STRIP4_START 180000
#define STRIP4_STOP 210000
#define RESTART 240000
unsigned long startTime = 0;
void setup()
{
// setup leds etc
}

void loop()
{
 unsigned long loopTime = millis() - startTime; // Calculate the time since last time the cycle was completed
 if (loopTime <= STRIP1_STOP) // Check if the time is less than STRIP1_STOP millis, and if so, run strip 1
 {
   // do sparkle for strip 1
 }
 else if (loopTime > STRIP2_START && loopTime <= STRIP2_STOP)
 {  
   // do sparkle for strip 2
 }
 else if (loopTime > STRIP3_START && loopTime <= STRIP3_STOP)
 {  
   // do sparkle for strip 3
 }
 else if (loopTime > STRIP4_START && loopTime <= STRIP4_STOP)
 {  
   // do sparkle for strip 4
 }
 else if (loopTime > RESTART) 
 {
   startTime = millis();
 }
}

Next challenge would be incorporating the strip number in the sparkle procedure.
If you really want to use 4 separate strips, each on their own pin, then we need to become creative and probably define multiple sparkle and ShowStrip functions.
If you keep it one strand, cut in 4 pieces, then we can simply expand the "Sparkle()" function to only do a subset of all pixels, like I described before:

void Sparkle(byte strip, byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(LEDS_PER_STRIP); // pick a random value 0...10
  Pixel = Pixel + (strip * LEDS_PER_STRIP); // shift the position so we get the right strip
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

   
ReplyQuote
(@mr_ben)
Active Member
Joined: 9 years ago
Posts: 7
Topic starter  

Fantastic!! Thank you!

I believe treating one "strip" in four sections will work! I am going to try and get these together as soon as possible and I will let you know my results.

B


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2860
 

Sounds good Mr_Ben .

If it doesn't work as you'd like, then we can still switch to 4 independent strips. 


   
ReplyQuote
(@mr_ben)
Active Member
Joined: 9 years ago
Posts: 7
Topic starter  

Hans,

Ok, I am now showing my cards here, I cannot get this to work, and it is far more to look at than other codes I have messed with before, I apologize, but I get an error saying "expected initializer before 'void' "

This is the code I put together from your code:

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 27
// Parameter 1 = number of pixels in strip
// Parameter 2 = 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)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

void setup() // 1 second = 1000 milliseconds
#define STRIP1_START 0
#define STRIP1_STOP  30000

#define STRIP2_START 60000
#define STRIP2_STOP  90000

#define STRIP3_START 120000
#define STRIP3_STOP  150000

#define STRIP4_START 180000
#define STRIP4_STOP  210000

#define RESTART      240000
#define unsigned long startTime = 0

void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to ‘off’
// setup leds etc
}

void loop()
{
 unsigned long loopTime = millis() - startTime; // Calculate the time since last time the cycle was completed
 if (loopTime <= STRIP1_STOP) // Check if the time is less than STRIP1_STOP millis, and if so, run strip 1
 {
   // do sparkle for strip 1
 }
 else if (loopTime > STRIP2_START && loopTime <= STRIP2_STOP)
 { 
   // do sparkle for strip 2
 }
 else if (loopTime > STRIP3_START && loopTime <= STRIP3_STOP)
 { 
   // do sparkle for strip 3
 }
 else if (loopTime > STRIP4_START && loopTime <= STRIP4_STOP)
 { 
   // do sparkle for strip 4
 }
 else if (loopTime > RESTART)
 {
   startTime = millis();
 }
}

void Sparkle(byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}
// REPLACE TO HERE

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

void Sparkle(byte strip, byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(LEDS_PER_STRIP); // pick a random value 0...10
  Pixel = Pixel + (strip * LEDS_PER_STRIP); // shift the position so we get the right strip
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2860
 

No problem ....

The first problem I have found in your code is right after

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

where you have:

void setup() // 1 second = 1000 milliseconds

You'll have to remove this line, as it tries to create a procedure called setup() but no code is following and you're redefining it again later on. I assume this is just a copy and paste mistake.

Now when this compiles, it will no do anything since you'll have to replace the

// do sparkle for strip x

lines with an actual function call. The Sparkle function in your code however is not prepared for multiple strip sections. So you'd have to use something like this to replace the sparkle function:

void Sparkle(byte strip, byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(LEDS_PER_STRIP); // pick a random value 0...10
  Pixel = Pixel + ((strip-1) * LEDS_PER_STRIP); // shift the position so we get the right strip
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

I have not tested this code by the way ... but it's a start for sure.

Now you need to replace each

// do sparkle for strip 1
// do sparkle for strip 2
// do sparkle for strip 3
// do sparkle for strip 4

with something like this:

Sparkle(1, 0xff, 0xff, 0xff, 0);
Sparkle(2, 0xff, 0xff, 0xff, 0);
Sparkle(3, 0xff, 0xff, 0xff, 0);
Sparkle(4, 0xff, 0xff, 0xff, 0);

Where "1" is the strip number (in "// do sparkle for strip 1").
I modified the sparkle procedure a little bit, since the strips start counting with "0" instead of "1". Nothing to worry about though, the code will handle it.

Hope this gets you going in the right direction, and don't be afraid to ask 


   
ReplyQuote
(@mr_ben)
Active Member
Joined: 9 years ago
Posts: 7
Topic starter  

OK,

Still not able to make things work, last error code was the 'setPixel' was not declared. Sorry but at a loss right here, and think it should be easy . . .

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 27
// Parameter 1 = number of pixels in strip
// Parameter 2 = 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)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

#define STRIP1_START 0
#define STRIP1_STOP  30000

#define STRIP2_START 60000
#define STRIP2_STOP  90000

#define STRIP3_START 120000
#define STRIP3_STOP  150000

#define RESTART      240000

unsigned long startTime = 0;

 // Calculate the time since last time the cycle was completed

void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to ‘off’
// setup leds etc
}

void loop()
{
 unsigned long loopTime = millis() - startTime;

 if (loopTime <= STRIP1_STOP) // Check if the time is less than STRIP1_STOP millis, and if so, run strip 1
 {
 Sparkle(1, 0xff, 0xff, 0xff, 0);// do sparkle for strip 1
 }
 else if (loopTime > STRIP2_START && loopTime <= STRIP2_STOP)
 { 
 Sparkle(2, 0xff, 0xff, 0xff, 0);  // do sparkle for strip 2
 }
 else if (loopTime > STRIP3_START && loopTime <= STRIP3_STOP)
 { 
 Sparkle(3, 0xff, 0xff, 0xff, 0);// do sparkle for strip 3
 }

 else if (loopTime > RESTART)
 {
   startTime = millis();
 }
}

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
}

void Sparkle(byte strip, byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(4); // pick a random value 0...10
  Pixel = Pixel + ((strip-1) * 20); // shift the position so we get the right strip
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}


   
ReplyQuote
(@mr_ben)
Active Member
Joined: 9 years ago
Posts: 7
Topic starter  

OK, I have spent some time with this, and tried some other effects to see if I can make them do what I would like, still unable to activate the sparkle effect on the second strip, but I have the color wipe effect working in sequence, and the first sparkle effect seems to fall in line nicely. Any suggestions on how to call the second sparkle? If I figure this out I feel like I would be able to set up as many pins as needed. MANY MANY MANY THANKS!

void loop() {
  colorWipe1(strip1.Color(0, 0, 200), 60); // Blue
  colorWipe1(strip1.Color(0, 0, 0), 0); // none
  delay(2000);

  for(int i=0; i<300; i++){
    Sparkle2(0xff, 0xff, 0xff, 10);} // Cant get this to activate ??
 
  colorWipe2(strip2.Color(0, 255, 0), 60); // Green
  colorWipe2(strip2.Color(0, 0, 0), 0); // none
  delay(2000);
 
  for(int i=0; i<300; i++){
    Sparkle1(0xff, 0xff, 0xff, 20);}
   
}

//******************* EFFECTS**********

//SPARKLE 1
void Sparkle1(byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,red,green,blue);
  strip1.show();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

//SPARKLE 2
void Sparkle2(byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,red,green,blue);
  strip2.show();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

//COLOR WIPE 1
void colorWipe1(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip1.numPixels(); i++) {
    strip1.setPixelColor(i, c);
    strip1.show();
    delay(wait);
  }
}

//COLOR WIPE 2
void colorWipe2(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip2.numPixels(); i++) {
    strip2.setPixelColor(i, c);
    strip2.show();
    delay(wait);
  }
}


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2860
 

No problem, let's see how I can help.

First off, did you use one strip or several individual strips?
Your first code suggests you use one strip, but your second code suggest multiple strips.

OK, you're first code:

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 27
// Parameter 1 = number of pixels in strip
// Parameter 2 = 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)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
#define STRIP1_START 0
#define STRIP1_STOP 30000
#define STRIP2_START 60000
#define STRIP2_STOP 90000
#define STRIP3_START 120000
#define STRIP3_STOP 150000
#define RESTART 240000
unsigned long startTime = 0;
 // Calculate the time since last time the cycle was completed
void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to ‘off’
// setup leds etc
}
void loop()
{
 unsigned long loopTime = millis() – startTime;
 if (loopTime <= STRIP1_STOP) // Check if the time is less than STRIP1_STOP millis, and if so, run strip 1
 {
 Sparkle(1, 0xff, 0xff, 0xff, 0);// do sparkle for strip 1
 }
 else if (loopTime > STRIP2_START && loopTime <= STRIP2_STOP)
 {  
 Sparkle(2, 0xff, 0xff, 0xff, 0); // do sparkle for strip 2
 }
 else if (loopTime > STRIP3_START && loopTime <= STRIP3_STOP)
 {  
 Sparkle(3, 0xff, 0xff, 0xff, 0);// do sparkle for strip 3
 }
 else if (loopTime > RESTART) 
 {
   startTime = millis();
 }
}
void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
}
void Sparkle(byte strip, byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(4); // pick a random value 0…10
  Pixel = Pixel + ((strip-1) * 20); // shift the position so we get the right strip
  setPixel(Pixel,red,green,blue);
  showStrip();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

Seems you forgot to add this at the end:

void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H 
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H 
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}
void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue); 
  }
  showStrip();
}

Do I read this right; you've used one strip and divided it in 20 sections, each 4 pixels long?
In the "Sparkle()" function you're choosing a random number (0...4) and then place it on one of 20 "strips".
This is why defining these values makes things more readable, because you call only for 4 strips (Sprakle()). This way (if done right) you can change these defined values as you se fit and the code will handle everything automatically ... 

Can you let me know what configuration you have in mind? Then I can optimize the code a bit ... 


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2860
 

p.s. when posting code:

1. Paste the code in the message and place one empty line after the code (if you need to type more).
2. Select the code and click the "source code" button (far right, next to the paragraph and smiley button).

This would make reading the article easier .. 


   
ReplyQuote
(@mr_ben)
Active Member
Joined: 9 years ago
Posts: 7
Topic starter  

Ok, I am a terrible communicator I will try to be clear : )
I was trying to do one strip but I could not clear some of the error codes I was getting by myself. As a result I used the first method of multiple pins and separated the strips accordingly.

I felt my code was taking up to much space so I only pasted what I thought was the important part and then neglected to tell you

I like the versatility of the multiple pin method, because I can understand the code (I guess enough , for future use)  and I can switch between lighting effects. My entire code that I came up with for this is below. My dilemma is that I cannot call the "sparkle2" effect...? I do see that in the color wipe code there is a specific need to specify which strip, but I could not figure out how to specify which sparkle effect.

As of now the sequence lights up like this

-colorWipe1 on strip1, then off

-delay, no activity on strip2 (and seems like a delay for the duration of the          sparkle2 effect)

-colorWipe2 on strip2, then off

-sparkle1 on strip1, then loop

How can I call the Sparkle effect for a specific strand in the loop?

#include <Adafruit_NeoPixel.h>
#define NUM_LEDS 15
#define PIN1 6
#define PIN2 5

Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUM_LEDS, PIN1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(NUM_LEDS, PIN2, NEO_GRB + NEO_KHZ800);

void setup() {
  strip1.begin();
  strip1.show(); // Initialize all pixels to 'off'
 
  strip2.begin();
  strip2.show(); // Initialize all pixels to 'off'
 
}
//***************************************

void loop() {
  colorWipe1(strip1.Color(0, 0, 200), 60); // Blue
  colorWipe1(strip1.Color(0, 0, 0), 0); // none
  delay(2000);

  for(int i=0; i<300; i++){
    Sparkle2(0xff, 0xff, 0xff, 10);} // Cant get this to activate ??
 
  colorWipe2(strip2.Color(0, 255, 0), 60); // Green
  colorWipe2(strip2.Color(0, 0, 0), 0); // none
  delay(2000);
 
  for(int i=0; i<300; i++){
    Sparkle1(0xff, 0xff, 0xff, 20);}
   
}


//
**************** EFFECTS*******


//SPARKLE 1
void Sparkle1(byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,red,green,blue);
  strip1.show();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}

//SPARKLE 2
void Sparkle2(byte red, byte green, byte blue, int SpeedDelay) {
  int Pixel = random(NUM_LEDS);
  setPixel(Pixel,red,green,blue);
  strip2.show();
  delay(SpeedDelay);
  setPixel(Pixel,0,0,0);
}


//COLOR WIPE 1
void colorWipe1(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip1.numPixels(); i++) {
    strip1.setPixelColor(i, c);
    strip1.show();
    delay(wait);
  }
}

//COLOR WIPE 2
void colorWipe2(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip2.numPixels(); i++) {
    strip2.setPixelColor(i, c);
    strip2.show();
    delay(wait);
  }
}



//
********************************
void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip1.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip1.setPixelColor(Pixel, strip1.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

   
ReplyQuote
Share: