Is it possible to animate multiple NEOPIXEL stripes in parallel via Arduino?

81 views Asked by At

I´m having an ongoing project for a good friend of mine. I´m pretty new to this programming stuff, so I´m forced to ask for help.

He wants to have some sort of cloud ceiling with a few LED stripes to show lighning effects. Here´s the tricky part. He already bought 4 24V stripes, but as far as I´m concerned, those should work for the project. I´ve gotten my handy on a really good-looking piece of code that resembles most of the properties needed for this project, but it also lacks a few things and I´m far too inexperienced to handle it myself.

First of all, he wants the stripes to animate one after one, but without any obvious order. I was thinking about putting in some RNG to do that job, but I failed miserably. There were not many more options besides killing the whole code, and I don´t really understand very much of it. So this part is also out of question.

The animation itself is great, I really love it. The only thing that disturbs me is the limitation of only 3 colours that are used in there. They also follow the same order and I´ve yet to figure out a way to randomize them, too

I would be more than happy if anyone could help me solving this issue.

Here´s the code, if anyone needs it.

#include "FastLED.h"   //Make sure to install the FastLED library into your Arduino IDE

//The total number of LEDs being used is 144
#define NUM_LEDS 60

// The data pin for the NeoPixel strip is connected to digital Pin 6 on the Arduino
#define DATA_PIN 4

//Initialise the LED array, the LED Hue (ledh) array, and the LED Brightness (ledb) array.
CRGB leds[NUM_LEDS];
byte ledh[NUM_LEDS];
byte ledb[NUM_LEDS];

const int LEDSpeed = 30; //Speed of the LED animation effect. Make sure not to exceed the maxLEDSpeed value.
int maxLEDSpeed = 50;    //Identifies the maximum speed of the LED animation sequence
int LEDposition=0;       //Identifies the LED position in the strip that the comet is currently at. The maximum position is NUM_LEDS-1  (eg. 143)
int oldPosition=0;       //Holds the previous position of the comet.

byte hue = 0;            //Stores the Leading LED's hue value (colour)
byte sat = 255;          //Stores the Leading LED's saturation value
byte tailHue = 0;        //Stores the Comet tail hue value
int tailLength = 8;      //determines the length of the tail.
byte hueRange = 20;      //Colour variation of the tail (greater values have greater variation
byte intensity = 200;    //The default brightness of the leading LED
byte tailbrightness= intensity / 2;  //Affects the brightness and length of the tail
int animationDelay = 0;  //The greater the animation delay, the slower the LED sequence. Calculated from LEDSpeed and MaxSpeed.

unsigned long waitTime = random(50, 5000);  //The wait time for each comet
unsigned long endTime;   //The time when we no longer have to wait for the next comet

int cometNumber = 3;     //Used to choose which comet colour to show (***Don't change this variable***)


//===================================================================================================================================================
// setup() : Is used to initialise the LED strip
//===================================================================================================================================================
void setup() {
    
    FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);                            //initialise the LED strip     
    selectNextComet();                                                                  //Select the next comet colour
}


//===================================================================================================================================================
// loop() : 
//===================================================================================================================================================
void loop(){
    showLED(LEDposition, hue, sat, intensity);

    //Adjust the hue of the tail so that it is a different colour from the leading LED. To reduce variation in tail colour, reduce the hueRange.
    if(hue>(254-hueRange)){
      tailHue = random((hue-hueRange),hue);
    } else {
      tailHue = random(hue, (hue+hueRange)); 
    }
    
    tailbrightness = random(50, 100);                      //Randomly select the brightness of the trailing LED (provides sparkling tail)

    
    leds[LEDposition]=CHSV((tailHue),sat,tailbrightness);  //Set the colour, saturation and brightness of the trailing LED
    fadeLEDs(tailLength);                                  //Fade the tail so that the tail brightness dwindles down to nothingness.
    setDelay(LEDSpeed);                                    //

    LEDposition++;
    if(LEDposition>(NUM_LEDS-1)){
      
      for(int i=0; i<50; i++){
        showLED(LEDposition, hue, sat, intensity);
        fadeLEDs(tailLength);
        setDelay(LEDSpeed);
      } 
      LEDposition=0;
      selectNextComet();                                  //Select the next comet colour
    }
  
}


//===================================================================================================================================================
// showLED() : is used to illuminate the LEDs 
//===================================================================================================================================================
void showLED(int pos, byte LEDhue, byte LEDsat, byte LEDbright){
  leds[pos] = CHSV(LEDhue,LEDsat,LEDbright);
  FastLED.show();
}


//===================================================================================================================================================
// fadeLEDs(): This function is used to fade the LEDs back to black (OFF) 
//===================================================================================================================================================
void fadeLEDs(int fadeVal){
  for (int i = 0; i<NUM_LEDS; i++){
    leds[i].fadeToBlackBy( fadeVal );
  }
}


//===================================================================================================================================================
// setDelay() : is where the speed of the LED animation sequence is controlled. The speed of the animation is controlled by the LEDSpeed variable.
//              and cannot go faster than the maxLEDSpeed variable.
//===================================================================================================================================================
void setDelay(int LSpeed){
  animationDelay = maxLEDSpeed - abs(LSpeed);
  delay(animationDelay);
}


//===================================================================================================================================================
//selectNextComet() : This is where we select either the Blue, the Pink or the White comet         
//===================================================================================================================================================
void selectNextComet(){
  cometNumber++;
  if(cometNumber>3){
    cometNumber=1;
  }

  switch(cometNumber){
    case 1:  {    //Blue Comet
      hue = 160;
      sat = 255;
      hueRange=20;
      break;
    }
 
    case 2:  {   //Pink Comet
      hue = 224;
      sat = 120;
      hueRange=10;
      break;
    }
    
    default: {   //White Comet
      hue = 0;
      sat = 0;
      hueRange = 0;
      break;
    }  
  }
}


//===================================================================================================================================================
// waitForNextComet() : Is where we either wait for 60 seconds for another comet to come, or initiate another comet with a button press.
//                      The button will only be "ACTIVE" while we are waiting for the next comet. It has no effect while a comet is currently running         
//===================================================================================================================================================

It´s all stated above.

0

There are 0 answers