Go Down

Topic: Multiple NeoPixel Led Strips (Read 862 times) previous topic - next topic

ArshiaKO

hi guys,

I have multiple led strips (WS2812B) and I'm having a hard time coding them.
Can anyone make a code that does 6 different effects on 6 different neopixel led strips?
 
Thanks!


UKHeliBob

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Knight_Sun

Not certain if this is what you were thinking of, it sort of stops the data stream. It dose give a neat effect on four channels with a fifth being the original signal. I only went to four as it matches the inputs of a standard AND gate. I found that fast_LED worked well unlike Neo_Pixels. Note* Red is a "analogWrite" and will give a very different look.   




// using a positive AND gate with this code will disrupt the digital signal of a Fast_LED Arduino.
// A input of AND gate to the arduino with fast_LED running 
// B input of AND gate to the arduino with "disrupter code" running.
// Y output of AND gate to the WS2812b.
// ws2812b will store the last code receved and hold it until signal returns

int ledcolor = 0;
int a = 3000; //this sets how long the stays one color or sequence for
int red = 5; //this sets the red led pin NOTE: it is analogWrite on digital pin, gives difrint effect.
int green = 8; //this sets the green led pin
int blue = 7; //this sets the blue led pin
int yellow = 6; //this sets the yellow led pin

void setup() { //this sets the output pins

pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(yellow, OUTPUT);

Serial.begin(9600);
}

void loop() {
int ledcolor = random(16); //this randomly selects a number between 0 and 15

Serial.print(ledcolor);

switch (ledcolor) {
 
case 0: //if ledcolor equals 0 then the led will turn red
analogWrite(red, HIGH);
delay(a);
analogWrite(red, LOW);
break;

case 1: //if ledcolor equals 1 then the led will turn green
digitalWrite(green, HIGH);
delay(a);
digitalWrite(green, LOW);
break;

case 2: //if ledcolor equals 2 then the led will turn blue
digitalWrite(blue, HIGH);
delay(a);
digitalWrite(blue, LOW);
break;

case 3: //if ledcolor equals 3 then the led will turn yellow
analogWrite(red, HIGH);
digitalWrite(green, HIGH);
delay(a);
analogWrite(red, LOW);
digitalWrite(green, LOW);
break;

case 4: //if ledcolor equals 4 then the led will turn cyan
analogWrite(red, HIGH);
digitalWrite(blue, HIGH);
delay(a);
analogWrite(red, LOW);
digitalWrite(blue, LOW);
break;

case 5: //if ledcolor equals 5 then the led will turn red
digitalWrite(yellow, HIGH);
delay(a);
digitalWrite(yellow, LOW);

case 6: //if ledcolor equals 6 then the led will turn magenta
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
delay(a);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
break;

case 7: //if ledcolor equals 7 then the led will turn white 3 on
analogWrite(red, HIGH);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
delay(a);
analogWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
break;

//4 led new

case 8: //if ledcolor equals 8 then the led will turn cyan
analogWrite(red, HIGH);
digitalWrite(blue, HIGH);
digitalWrite(yellow, HIGH);
delay(a);
digitalWrite(yellow, LOW);
analogWrite(red, LOW);
digitalWrite(blue, LOW);
break;

case 9: //if ledcolor equals 9 then the led will turn magenta
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
delay(a);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
break;

case 10: //if ledcolor equals 10 then the led will turn 3 on
analogWrite(red, HIGH);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
digitalWrite(yellow, HIGH);
delay(a);
digitalWrite(yellow, LOW);
analogWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
break;

case 11: //if ledcolor equals 11 then the led will turn 3 on
analogWrite(red, HIGH);
digitalWrite(green, HIGH);
digitalWrite(yellow, HIGH);
delay(a);
analogWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(yellow, LOW);
break;

case 12: //if ledcolor equals 12 then the led will turn white 3 on
analogWrite(red, HIGH);
digitalWrite(yellow, HIGH);
digitalWrite(blue, HIGH);
delay(a);
analogWrite(red, LOW);
digitalWrite(yellow, LOW);
digitalWrite(blue, LOW);
break;

case 13: //if ledcolor equals 13 then the led will turn white
digitalWrite(yellow, HIGH);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
delay(a);
digitalWrite(yellow, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
break;

case 14: //if ledcolor equals 14 then the led will turn 4 on
analogWrite(red, HIGH);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
digitalWrite(yellow, HIGH);
delay(a);
analogWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
digitalWrite(yellow, LOW);
break;

case 15: //if ledcolor equals 15 then the led will turn 4 on
analogWrite(red, HIGH);
digitalWrite(green, HIGH);
digitalWrite(blue, HIGH);
digitalWrite(yellow, HIGH);
delay(a);
analogWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, LOW);
digitalWrite(yellow, LOW);
}

}

Paul__B

Thank you for your contribution, but please go and read the forum instructions so that you can go back and modify your original post (not re-post it) - using the "More -> Modify" option below the right hand corner of your post - to mark up your code as such using the "</>" icon in the posting window.  Just highlight each section of code (or output if you need to post that) from the IDE and click the icon.

In fact, the IDE has a "copy for forum" link to put these markings on a highlighted block for you so you then just paste it here in a posting window.  But even before doing that, don't forget to use the "Auto-Format" (Ctrl-T) option first to make it easy to read.  If you do not post it as "code" it can as you now see, be quite garbled and is always more difficult to read.

It is inappropriate to attach it as a ".ino" file unless it is clearly too long to include in the post proper.  People can usually see the mistakes directly and do not want to have to actually load it in their own IDE.  And that would also assume they are using a PC and have the IDE running on that PC.

Your use of blank space is not bad.  Do use blank lines, but only between complete functional blocks.

sterretje

Not certain if this is what you were thinking of, it sort of stops the data stream. It dose give a neat effect on four channels with a fifth being the original signal. I only went to four as it matches the inputs of a standard AND gate. I found that fast_LED worked well unlike Neo_Pixels. Note* Red is a "analogWrite" and will give a very different look.

...
...   
I'm not sure how your solution relates to addressable led strips. Am I missing something?
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

david_2018

The main problem you are going to have with running six different effects on six different neopixel strips is that the code for generating the effects cannot be blocking.  Each time through loop() you will need to check if it is time to update an individual neopixel strip, and if it is then you update the LED pattern for that particular strip, then continue on checking to see if the other strips need updating.  You cannot sit in a 'while' or 'for' loop, or use delay(), to generate the effect for any particular strip, because that will prevent updating the others.  

Grumpy_Mike

#6
Jun 02, 2019, 07:48 am Last Edit: Jun 02, 2019, 08:18 am by Grumpy_Mike
Yes that is right.
Here is an example of running two strips with two patterns at the same time.
Code: [Select]

// using a state machine to drive two patterns on two strings at the same time
// By Mike Cook Jan 2019
// see https://github.com/FastLED/FastLED/wiki/Multiple-Controller-Examples for full discussion

#include "FastLED.h"

#define PIN_FOR_1   6 // pin connected to NeoPixels strip 1
#define PIN_FOR_2   7 // pin connected to NeoPixels strip 2
#define NUM_LEDS1 5   // number of LEDs in strip 1
#define NUM_LEDS2 6   // number of LEDs in strip 1
#define NUM_STRIPS  2 // how many strips you have

CRGB strip1[NUM_LEDS1];
CRGB strip2[NUM_LEDS2];

CLEDController *controllers[NUM_STRIPS];

// how often each pattern updates
unsigned long pattern1Interval  = 400;
unsigned long pattern2Interval  = 900;
// for millis() when last update occurred
unsigned long lastUpdateP1 = 0;
unsigned long lastUpdateP2 = 0;  
// state variables for patterns
int p1State = 0 ;
int p2State = 0 ;
uint8_t gBrightness = 255;

void setup() {
   controllers[0] = &FastLED.addLeds<WS2812,PIN_FOR_1>(strip1, NUM_LEDS1);
   controllers[1] = &FastLED.addLeds<WS2812,PIN_FOR_2>(strip2, NUM_LEDS2);
   // wipes the LED buffers
    wipe1(0,0,0);
    wipe2(0,0,0);
}

void loop(){
if(millis() - lastUpdateP1 > pattern1Interval) updatePattern1();
if(millis() - lastUpdateP2 > pattern2Interval) updatePattern2();
}

// Note both patterns are essentially the same sort of display for simplicity - change to suite
void updatePattern1(){ // pattern 1 a walking red led
   strip2[p1State].setRGB(128,0,0); // turn on next led in pattern
   int lastLed = p1State -1;        // find LED to turn off
   if (lastLed < 0) {               // wrap round count
      lastLed = NUM_LEDS1 -1;
   }
   strip1[lastLed] = 0x00;     // turn off last LED we set
   p1State ++;                 // move on state variable for the next time we enter this
   if(p1State >= NUM_LEDS1){   // wrap round the state
    p1State = 0;
   }
   controllers[0]->showLeds(gBrightness); // update display
   lastUpdateP1 = millis();               // to calculate next update
}

void updatePattern2(){ // pattern 2 a walking green LED
   strip2[p2State].setRGB(0,128,0); // turn on next led in pattern  
   int lastLed = p2State -1;        // find LED to turn off
   if (lastLed < 0) {               // wrap round count if needed
      lastLed = NUM_LEDS2 -1;
   }
   strip2[lastLed] = 0x00;    // turn off last LED we set
   p2State ++;                // move on state variable for the next time we enter this
   if(p2State >= NUM_LEDS2){  // wrap round the state
    p2State = 0;
   }
   controllers[1]->showLeds(gBrightness);  // update display
   lastUpdateP2 = millis();                // to calculate next update
}

void wipe1(byte r,byte g, byte b){
     for(int i=0;i<NUM_LEDS1;i++){
       strip1[i].setRGB(r,g,b);
       }
}

void wipe2(byte r,byte g, byte b){
     for(int i=0;i<NUM_LEDS2;i++){
       strip2[i].setRGB(r,g,b);
       }
}


Note these are just simple patterns to illustrate mainly the way of achieving the switching between the two. More complex patterns would still have to be implemented as a state machine.

Also note that the code could be made more compact but it is spread out so that it is easier to follow.

Go Up