HOW TO CONNECT TWO CODES TOGETHER?

How to connect this two LED design codes together.no special functions just need to run one design after another in Pixel LED bulb series(50 LEDS).

Code 1:

#include <FastLED.h>

#define DATA_PIN     2
#define NUM_LEDS    50

CRGB leds[NUM_LEDS];

void setup() {
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);

}

void loop() {
P_flag();
//P_2();
P_flagColors();

}

void P_flag() {
int TIME_1 = 20;

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Blue;
  FastLED.show();
  delay(TIME_1);
}
for (int i = 0; i < 4 * NUM_LEDS / 5; i++) {
  leds[i] = CRGB::Yellow;
  FastLED.show();
  delay(TIME_1);
}
for (int i = 0; i < 3 * NUM_LEDS / 5; i++) {
  leds[i] = CRGB::Red;
  FastLED.show();
  delay(TIME_1);
}

for (int i = 0; i < 2 * NUM_LEDS / 5; i++) {
  leds[i] = CRGB::White;
  FastLED.show();
  delay(TIME_1);
}

for (int i = 0; i < NUM_LEDS / 5; i++) {
  leds[i] = CRGB::OrangeRed;
  FastLED.show();
  delay(TIME_1);
}
delay(5000);
for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Black;
  FastLED.show();
  delay(20);
}
}

void P_2() {

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Red;
  leds[i + 1] = CRGB::Red;
  leds[i + 2] = CRGB::Blue;
  FastLED.show();
  delay(10);
  leds[i] = CRGB::Black;
  FastLED.show();
}

for (int i = NUM_LEDS; i > 0; i--) {
  leds[i] = CRGB::Red;
  leds[i + 1] = CRGB::Red;
  leds[i + 2] = CRGB::Blue;
  FastLED.show();
  delay(10);
  leds[i - 3] = CRGB::Black;
  FastLED.show();
}

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::BurlyWood ;
  leds[i + 1] = CRGB::BurlyWood ;
  leds[i + 2] = CRGB::BurlyWood ;
  FastLED.show();
  delay(10);
  leds[i] = CRGB::Black;
  FastLED.show();
}

for (int i = NUM_LEDS; i > 0; i--) {
  leds[i] = CRGB::DeepSkyBlue ;
  leds[i + 1] = CRGB::DeepSkyBlue ;
  leds[i + 2] = CRGB::DeepSkyBlue ;
  FastLED.show();
  delay(10);
  leds[i - 3] = CRGB::Black;
  FastLED.show();
}
}

void P_flagColors() {
for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Blue;
}
FastLED.show();
delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Yellow;

}
FastLED.show();
delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Red;
}
FastLED.show();
delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::White;
}
FastLED.show();
delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::OrangeRed;
}
FastLED.show();
delay(1000);
}

Code 2:

#include <FastLED.h>

FASTLED_USING_NAMESPACE



#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
#warning "Requires FastLED 3.1 or later; check github for latest code."
#endif

#define DATA_PIN    2

#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS    50
CRGB leds[NUM_LEDS];

#define BRIGHTNESS          96
#define FRAMES_PER_SECOND  120

void setup() {
delay(3000); // 3 second delay for recovery

// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
}


// List of patterns to cycle through.  Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };

uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns

void loop()
{
// Call the current pattern function once, updating the 'leds' array
gPatterns[gCurrentPatternNumber]();

// send the 'leds' array out to the actual LED strip
FastLED.show();  
// insert a delay to keep the framerate modest
FastLED.delay(1000/FRAMES_PER_SECOND); 

// do some periodic updates
EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
}

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}

void rainbow() 
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter() 
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter) 
{
if( random8() < chanceOfGlitter) {
  leds[ random16(NUM_LEDS) ] += CRGB::White;
}
}

void confetti() 
{
// random colored speckles that blink in and fade smoothly
fadeToBlackBy( leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
}

void sinelon()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16( 13, 0, NUM_LEDS-1 );
leds[pos] += CHSV( gHue, 255, 192);
}

void bpm()
{
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
uint8_t BeatsPerMinute = 62;
CRGBPalette16 palette = PartyColors_p;
uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
for( int i = 0; i < NUM_LEDS; i++) { //9948
  leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
}
}

void juggle() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 0;
for( int i = 0; i < 8; i++) {
  leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
  dothue += 32;
}
}

Please read read this before posting a programming question then post your code using code tags to avoid it turning into italics

Have you tried to combine the two programs ?

yes.and I tried to use some guides in internet too.but I ended up in different errors about redefining like things.I have used one setup and loop for the code but still got errors

Please post the program that represents your best attempt and tell us in detail what it actually does and what you want it to do that is different. It will make it much easier to focus on the parts you need help with rather than wasting time on things that you can do.

Also post the error message.

...R

I tried 2 codes separately and they work well.this codes containing LED design patterns to WS2811 Chipped RGB LED strips so they can light up in many ways.I'm trying to combine 2 patterns in these codes to make one code so that after one deign other one will run in a loop.

Combined Code I Tried to Made :

#include 

#define DATA_PIN     2
#define NUM_LEDS    50
FASTLED_USING_NAMESPACE

#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
#warning "Requires FastLED 3.1 or later; check github for latest code."
#endif
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

#define BRIGHTNESS          96
#define FRAMES_PER_SECOND  120

CRGB leds[NUM_LEDS];

void setup() {
  FastLED.addLeds(leds, NUM_LEDS);
  delay(3000); // 3 second delay for recovery
  
  // tell FastLED about the LED strip configuration
  FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

  // set master brightness control
  FastLED.setBrightness(BRIGHTNESS);

}

void loop() {
  P_flag();
  //P_2();
  P_flagColors();
// Call the current pattern function once, updating the 'leds' array
  gPatterns[gCurrentPatternNumber]();

  // send the 'leds' array out to the actual LED strip
  FastLED.show();  
  // insert a delay to keep the framerate modest
  FastLED.delay(1000/FRAMES_PER_SECOND); 

  // do some periodic updates
  EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
  EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodic
}

void P_flag() {
  int TIME_1 = 20;

  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::Blue;
    FastLED.show();
    delay(TIME_1);
  }
  for (int i = 0; i < 4 * NUM_LEDS / 5; i++) {
    leds[i] = CRGB::Yellow;
    FastLED.show();
    delay(TIME_1);
  }
  for (int i = 0; i < 3 * NUM_LEDS / 5; i++) {
    leds[i] = CRGB::Red;
    FastLED.show();
    delay(TIME_1);
  }

  for (int i = 0; i < 2 * NUM_LEDS / 5; i++) {
    leds[i] = CRGB::White;
    FastLED.show();
    delay(TIME_1);
  }

  for (int i = 0; i < NUM_LEDS / 5; i++) {
    leds[i] = CRGB::OrangeRed;
    FastLED.show();
    delay(TIME_1);
  }
  delay(5000);
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::Black;
    FastLED.show();
    delay(20);
  }
}

void P_2() {

  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::Red;
    leds[i + 1] = CRGB::Red;
    leds[i + 2] = CRGB::Blue;
    FastLED.show();
    delay(10);
    leds[i] = CRGB::Black;
    FastLED.show();
  }

  for (int i = NUM_LEDS; i > 0; i--) {
    leds[i] = CRGB::Red;
    leds[i + 1] = CRGB::Red;
    leds[i + 2] = CRGB::Blue;
    FastLED.show();
    delay(10);
    leds[i - 3] = CRGB::Black;
    FastLED.show();
  }

  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::BurlyWood ;
    leds[i + 1] = CRGB::BurlyWood ;
    leds[i + 2] = CRGB::BurlyWood ;
    FastLED.show();
    delay(10);
    leds[i] = CRGB::Black;
    FastLED.show();
  }

  for (int i = NUM_LEDS; i > 0; i--) {
    leds[i] = CRGB::DeepSkyBlue ;
    leds[i + 1] = CRGB::DeepSkyBlue ;
    leds[i + 2] = CRGB::DeepSkyBlue ;
    FastLED.show();
    delay(10);
    leds[i - 3] = CRGB::Black;
    FastLED.show();
  }
}

void P_flagColors() {
  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::Blue;
  }
  FastLED.show();
  delay(1000);

  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::Yellow;

  }
  FastLED.show();
  delay(1000);

  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::Red;
  }
  FastLED.show();
  delay(1000);

  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::White;
  }
  FastLED.show();
  delay(1000);

  for (int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CRGB::OrangeRed;
  }
  FastLED.show();
  delay(1000);
}
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

void nextPattern()
{
  // add one to the current pattern number, and wrap around at the end
  gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}

void rainbow() 
{
  // FastLED's built-in rainbow generator
  fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter() 
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  rainbow();
  addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter) 
{
  if( random8() < chanceOfGlitter) {
    leds[ random16(NUM_LEDS) ] += CRGB::White;
  }
}

void confetti() 
{
  // random colored speckles that blink in and fade smoothly
  fadeToBlackBy( leds, NUM_LEDS, 10);
  int pos = random16(NUM_LEDS);
  leds[pos] += CHSV( gHue + random8(64), 200, 255);
}

void sinelon()
{
  // a colored dot sweeping back and forth, with fading trails
  fadeToBlackBy( leds, NUM_LEDS, 20);
  int pos = beatsin16( 13, 0, NUM_LEDS-1 );
  leds[pos] += CHSV( gHue, 255, 192);
}

void bpm()
{
  // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
  uint8_t BeatsPerMinute = 62;
  CRGBPalette16 palette = PartyColors_p;
  uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
  for( int i = 0; i < NUM_LEDS; i++) { //9948
    leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
  }
}

void juggle() {
  // eight colored dots, weaving in and out of sync with each other
  fadeToBlackBy( leds, NUM_LEDS, 20);
  byte dothue = 0;
  for( int i = 0; i < 8; i++) {
    leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
    dothue += 32;
  }
}

Error Message I Got :

Arduino: 1.8.9 (Windows 7), Board: "Arduino/Genuino Uno"

In file included from C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\Flag.ino:2:0:

C:\Users\~\Documents\Arduino\libraries\FastLED-3.2.0/FastLED.h:17:21: note: #pragma message: FastLED version 3.002.000

 #    pragma message "FastLED version 3.002.000"

                     ^

test:13:19: error: redefinition of 'CRGB leds [50]'

 CRGB leds[NUM_LEDS];

                   ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\Flag.ino:7:6: note: 'CRGB leds [50]' previously declared here

 CRGB leds[NUM_LEDS];

      ^

test:18:19: error: redefinition of 'CRGB leds [50]'

 CRGB leds[NUM_LEDS];

                   ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\Flag.ino:7:6: note: 'CRGB leds [50]' previously declared here

 CRGB leds[NUM_LEDS];

      ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\test.ino: In function 'void setup()':

test:20:6: error: redefinition of 'void setup()'

 void setup() {

      ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\Flag.ino:9:6: note: 'void setup()' previously defined here

 void setup() {

      ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\test.ino: In function 'void loop()':

test:33:6: error: redefinition of 'void loop()'

 void loop() {

      ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\Flag.ino:14:6: note: 'void loop()' previously defined here

 void loop() {

      ^

test:38:3: error: 'gPatterns' was not declared in this scope

   gPatterns[gCurrentPatternNumber]();

   ^

test:38:13: error: 'gCurrentPatternNumber' was not declared in this scope

   gPatterns[gCurrentPatternNumber]();

             ^

test:46:32: error: 'gHue' was not declared in this scope

   EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow

                                ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\test.ino: In function 'void P_flag()':

test:50:6: error: redefinition of 'void P_flag()'

 void P_flag() {

      ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\Flag.ino:21:6: note: 'void P_flag()' previously defined here

 void P_flag() {

      ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\test.ino: In function 'void P_2()':

test:88:6: error: redefinition of 'void P_2()'

 void P_2() {

      ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\Flag.ino:59:6: note: 'void P_2()' previously defined here

 void P_2() {

      ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\test.ino: In function 'void P_flagColors()':

test:131:6: error: redefinition of 'void P_flagColors()'

 void P_flagColors() {

      ^

C:\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\Flag.ino:102:6: note: 'void P_flagColors()' previously defined here

 void P_flagColors() {

      ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\test.ino: In function 'void nextPattern()':

test:168:3: error: 'gCurrentPatternNumber' was not declared in this scope

   gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);

   ^

test:168:69: error: 'gPatterns' was not declared in this scope

   gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);

                                                                     ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\test.ino:163:31: note: in definition of macro 'ARRAY_SIZE'

 #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

                               ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\test.ino: In function 'void rainbow()':

test:174:33: error: 'gHue' was not declared in this scope

   fill_rainbow( leds, NUM_LEDS, gHue, 7);

                                 ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\test.ino: In function 'void confetti()':

test:196:22: error: 'gHue' was not declared in this scope

   leds[pos] += CHSV( gHue + random8(64), 200, 255);

                      ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\test.ino: In function 'void sinelon()':

test:204:22: error: 'gHue' was not declared in this scope

   leds[pos] += CHSV( gHue, 255, 192);

                      ^

C:\~\Downloads\Pixel-LED-Decorations-master\Pixel-LED-Decorations-master\Flag\test.ino: In function 'void bpm()':

test:214:41: error: 'gHue' was not declared in this scope

     leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));

                                         ^

exit status 1
redefinition of 'CRGB leds [50]'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

How many arrays do you need?

honestly I don't know the answer for that.what I'm trying to do is running the 2 codes continuously one after another

check this

#include 

FASTLED_USING_NAMESPACE



#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
#warning "Requires FastLED 3.1 or later; check github for latest code."
#endif

#define DATA_PIN    2

#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS    50
CRGB leds[NUM_LEDS];

#define BRIGHTNESS          96
#define FRAMES_PER_SECOND  120

void setup() {
delay(3000); // 3 second delay for recovery

// tell FastLED about the LED strip configuration
FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
//FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
}


// List of patterns to cycle through.  Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };

uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns

void loop()
{
P_flag();
//P_2();
P_flagColors();

// Call the current pattern function once, updating the 'leds' array
gPatterns[gCurrentPatternNumber]();

// send the 'leds' array out to the actual LED strip
FastLED.show();  
// insert a delay to keep the framerate modest
FastLED.delay(1000/FRAMES_PER_SECOND); 

// do some periodic updates
EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
}

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}

void rainbow() 
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter() 
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter) 
{
if( random8() < chanceOfGlitter) {
  leds[ random16(NUM_LEDS) ] += CRGB::White;
}
}

void confetti() 
{
// random colored speckles that blink in and fade smoothly
fadeToBlackBy( leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
}

void sinelon()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16( 13, 0, NUM_LEDS-1 );
leds[pos] += CHSV( gHue, 255, 192);
}

void bpm()
{
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
uint8_t BeatsPerMinute = 62;
CRGBPalette16 palette = PartyColors_p;
uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
for( int i = 0; i < NUM_LEDS; i++) { //9948
  leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
}
}

void juggle() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 0;
for( int i = 0; i < 8; i++) {
  leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
  dothue += 32;
}
}

void P_flag() {
int TIME_1 = 20;

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Blue;
  FastLED.show();
  delay(TIME_1);
}
for (int i = 0; i < 4 * NUM_LEDS / 5; i++) {
  leds[i] = CRGB::Yellow;
  FastLED.show();
  delay(TIME_1);
}
for (int i = 0; i < 3 * NUM_LEDS / 5; i++) {
  leds[i] = CRGB::Red;
  FastLED.show();
  delay(TIME_1);
}

for (int i = 0; i < 2 * NUM_LEDS / 5; i++) {
  leds[i] = CRGB::White;
  FastLED.show();
  delay(TIME_1);
}

for (int i = 0; i < NUM_LEDS / 5; i++) {
  leds[i] = CRGB::OrangeRed;
  FastLED.show();
  delay(TIME_1);
}
delay(5000);
for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Black;
  FastLED.show();
  delay(20);
}
}

void P_2() {

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Red;
  leds[i + 1] = CRGB::Red;
  leds[i + 2] = CRGB::Blue;
  FastLED.show();
  delay(10);
  leds[i] = CRGB::Black;
  FastLED.show();
}

for (int i = NUM_LEDS; i > 0; i--) {
  leds[i] = CRGB::Red;
  leds[i + 1] = CRGB::Red;
  leds[i + 2] = CRGB::Blue;
  FastLED.show();
  delay(10);
  leds[i - 3] = CRGB::Black;
  FastLED.show();
}

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::BurlyWood ;
  leds[i + 1] = CRGB::BurlyWood ;
  leds[i + 2] = CRGB::BurlyWood ;
  FastLED.show();
  delay(10);
  leds[i] = CRGB::Black;
  FastLED.show();
}

for (int i = NUM_LEDS; i > 0; i--) {
  leds[i] = CRGB::DeepSkyBlue ;
  leds[i + 1] = CRGB::DeepSkyBlue ;
  leds[i + 2] = CRGB::DeepSkyBlue ;
  FastLED.show();
  delay(10);
  leds[i - 3] = CRGB::Black;
  FastLED.show();
}
}

void P_flagColors() {
for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Blue;
}
FastLED.show();
delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Yellow;

}
FastLED.show();
delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Red;
}
FastLED.show();
delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::White;
}
FastLED.show();
delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::OrangeRed;
}
FastLED.show();
delay(1000);
}

test_user_12345: honestly I don't know the answer for that.what I'm trying to do is running the 2 codes continuously one after another

You have to look through the two programs to see if there are overlapping definitions of variables or functions. If there are then either you don't need the duplicate in the combined code or you need to give the duplicate a different name to keep it separate.

...R

Done.

Just download the script and modify settings for your own convenience (num_leds, comment second led strip) and it will work.

Have a nice day :slight_smile:

FASTLEDMERGED2.ino (4.67 KB)

LOTHAR2048's code Posted inline as it should ALWAYS be...

#include 

FASTLED_USING_NAMESPACE



#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
#warning "Requires FastLED 3.1 or later; check github for latest code."
#endif

#define DATA_PIN    D1
#define DATA_PIN2   D2  // SECOND STRIP IF YOU NEED MORE JUST ADD ONE MORE AND IT WILL SHOW THE SAME.
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS    28
CRGB leds[NUM_LEDS];

#define BRIGHTNESS          96
#define FRAMES_PER_SECOND  120

void setup() {
delay(3000); // 3 second delay for recovery

// tell FastLED about the LED strip configuration
FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); // SECOND STRIP IF YOU NEED MORE JUST ADD ONE MORE AND IT WILL SHOW THE SAME.
//FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
}


// List of patterns to cycle through.  Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { P_flag, P_flagColors, rainbow, rainbowWithGlitter, confetti, sinelon, juggle, bpm };

uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns

void loop()
{
// Call the current pattern function once, updating the 'leds' array
gPatterns[gCurrentPatternNumber]();

// send the 'leds' array out to the actual LED strip
FastLED.show(); 
// insert a delay to keep the framerate modest
FastLED.delay(1000/FRAMES_PER_SECOND);

// do some periodic updates
EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
}

#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))

void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
}

void P_flag() {
int TIME_1 = 20;

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Blue;
  FastLED.show();
  delay(TIME_1);
}
for (int i = 0; i < 4 * NUM_LEDS / 5; i++) {
  leds[i] = CRGB::Yellow;
  FastLED.show();
  delay(TIME_1);
}
for (int i = 0; i < 3 * NUM_LEDS / 5; i++) {
  leds[i] = CRGB::Red;
  FastLED.show();
  delay(TIME_1);
}

for (int i = 0; i < 2 * NUM_LEDS / 5; i++) {
  leds[i] = CRGB::White;
  FastLED.show();
  delay(TIME_1);
}

for (int i = 0; i < NUM_LEDS / 5; i++) {
  leds[i] = CRGB::OrangeRed;
  FastLED.show();
  delay(TIME_1);
}
delay(5000);
for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Black;
  FastLED.show();
  delay(20);
}
}

void P_flagColors() {
for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Blue;
}
FastLED.show();
delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Yellow;

}
FastLED.show();
delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::Red;
}
FastLED.show();
delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::White;
}
FastLED.show();
delay(1000);

for (int i = 0; i < NUM_LEDS; i++) {
  leds[i] = CRGB::OrangeRed;
}

FastLED.show();
delay(1000);
}

void rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter()
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter)
{
if( random8() < chanceOfGlitter) {
  leds[ random16(NUM_LEDS) ] += CRGB::White;
}
}

void confetti()
{
// random colored speckles that blink in and fade smoothly
fadeToBlackBy( leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
}

void sinelon()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16( 13, 0, NUM_LEDS-1 );
leds[pos] += CHSV( gHue, 255, 192);
}

void bpm()
{
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
uint8_t BeatsPerMinute = 62;
CRGBPalette16 palette = PartyColors_p;
uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
for( int i = 0; i < NUM_LEDS; i++) { //9948
  leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
}
}

void juggle() {
// eight colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 0;
for( int i = 0; i < 8; i++) {
  leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
  dothue += 32;
}
}