Add sketch 2 into sketch 1 and activate on button press 5

I am a total newbie to arduino and have used it to control the programmable led strips in a touchscreen jukebox I have built. The first sketch changes colour patterns through button presses 1 to 4 but I want to add the RGB Active sketch to change the lights via the Gravity analog sound sensor via button press 5.
I have tried to work it out but keep ketting compile errors so any help would be appreciated.

Sketch 1

#include <FastLED.h>

#define LED_PIN     7
#define BTN_PIN     5
#define NUM_LEDS    122
#define BRIGHTNESS  200
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB
#define UPDATES_PER_SECOND 200

CRGB leds[NUM_LEDS];
 
int counter = 0;
int buttonState = 0;

CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;

void setup() {
    delay( 1500 ); // power-up safety delay
    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    FastLED.setBrightness(  BRIGHTNESS );
    pinMode(BTN_PIN, INPUT_PULLUP);
    Serial.begin(9600);

    currentPalette = RainbowColors_p;
    currentBlending = LINEARBLEND;
}

void loop()
{
    ChangePalettePeriodically();
    
    static uint8_t startIndex = 0;
    startIndex = startIndex + 1; /* motion speed */
    
    FillLEDsFromPaletteColors( startIndex);
    
    FastLED.show();
    FastLED.delay(1000 / UPDATES_PER_SECOND);
}

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
    uint8_t brightness = 200;
    
    for( int i = 0; i < NUM_LEDS; i++) {
        leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;
    }
}

void ChangePalettePeriodically()
{
  Serial.println(digitalRead(BTN_PIN));

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if(digitalRead(BTN_PIN) == LOW) {
    counter = counter + 1;
    delay(130);
  }

  if(counter == 4) {
    counter = 0;
  }

  if( counter ==  0)  { currentPalette = RainbowColors_p;        currentBlending = LINEARBLEND; }
  if( counter == 1)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }
  if( counter == 2)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }
  if( counter == 3)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }
  if( counter == 4)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
}

// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
    for( int i = 0; i < 16; i++) {
        currentPalette[i] = CHSV( random8(), 255, random8());
    }
}

void SetupBlackAndWhiteStripedPalette()
{
    // 'black out' all 16 palette entries...
    fill_solid( currentPalette, 16, CRGB::Black);
    // and set every fourth one to white.
    currentPalette[0] = CRGB::White;
    currentPalette[4] = CRGB::White;
    currentPalette[8] = CRGB::White;
    currentPalette[12] = CRGB::White;
    
}

// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
    CRGB purple = CHSV( HUE_PURPLE, 255, 255);
    CRGB green  = CHSV( HUE_GREEN, 255, 255);
    CRGB black  = CRGB::Black;
    
    currentPalette = CRGBPalette16(
                                   green,  green,  black,  black,
                                   purple, purple, black,  black,
                                   green,  green,  black,  black,
                                   purple, purple, black,  black );
}

const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
    CRGB::Red,
    CRGB::Gray, // 'white' is too bright compared to red and blue
    CRGB::Blue,
    CRGB::Black,
    
    CRGB::Red,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Black,
    
    CRGB::Red,
    CRGB::Red,
    CRGB::Gray,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Blue,
    CRGB::Black,
    CRGB::Black
};

Sketch 2

//NOTE:-ADJUST/SET BY POTENTIOMETER OF SOUND SENSOR IF LESS NUMBER OF PATTERN OBSERVE

#include <FastLED.h>

int r=152;
int g=0;
int b=10;

#define LED_PIN 7 //CONNECT DATA PIN OF PIXEL WITH 5 NUMBER PIN OF ARDUINO
#define NUM_LEDS 122 //CHANGE THE VALUE IF YOU WANT TO USE DIFFRENT NUMBER OF LED IN YOUR STRIP,HERE IN MY STRIP NUMBER OF LED IS 60 SO I SET IT 60.

CRGB leds[NUM_LEDS];
CRGB led[NUM_LEDS];
int s=0;

void setup() {

FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
for (int i = NUM_LEDS/2; i >= 0; i--)
{
leds[i] = CRGB ( r,g,b);
leds[NUM_LEDS-i] = CRGB (r,g,b );
delay(40);
FastLED.show();
}
Serial.begin(9600);
pinMode(A0,INPUT);

}
void loop()
{
s=analogRead(A0);
s=s*2;
// Serial.println(s);
// delay(50);
if((s>=450)&&(s<=550))
{
leds[(NUM_LEDS/2)-1]=CRGB (0, 0, 255);
leds[NUM_LEDS/2]=CRGB (0, 0, 255);
}
else if((s>=400)&&(s<=450))
{
leds[(NUM_LEDS/2)-1]=CRGB (153, 153, 0);
leds[NUM_LEDS/2]=CRGB (153, 153, 0);
}
else if((s>=350)&&(s<=400))
{
leds[(NUM_LEDS/2)-1]=CRGB (255, 50, 255);
leds[NUM_LEDS/2]=CRGB (255, 50, 255);
}
else if((s>=300)&&(s<=350))
{
leds[(NUM_LEDS/2)-1]=CRGB (10, 25, 217);
leds[NUM_LEDS/2]=CRGB (10, 25, 217);
}

else if((s>=276)&&(s<=300))

{
leds[(NUM_LEDS/2)-1]=CRGB (50, 50, 150);
leds[NUM_LEDS/2]=CRGB (50, 50, 150);
}
else if((s>=250)&&(s<=275))
{
leds[(NUM_LEDS/2)-1]=CRGB (230, 0, 10);
leds[NUM_LEDS/2]=CRGB (230, 0, 10);
}
else if((s>=235)&&(s<=250))
{
leds[(NUM_LEDS/2)-1]=CRGB (0, 160, 0);
leds[NUM_LEDS/2]=CRGB (0, 160, 0);
}
else if((s>=200)&&(s<=230))
{
leds[(NUM_LEDS/2)-1]=CRGB (1, 0, 1);
leds[NUM_LEDS/2]=CRGB (1, 0, 1);
}
else
{
leds[(NUM_LEDS/2)-1] = CRGB ( r,s-100,b);
leds[NUM_LEDS/2] = CRGB ( r,s-100,b);
}
for (int i = 0; i <= ((NUM_LEDS/2)-2); i++)
{
leds[i] = leds[i+1];
leds[NUM_LEDS-1-i] = leds[(NUM_LEDS)-i-2];

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

}

Please read this.
http://www.thebox.myzen.co.uk/Tutorial/Merging_Code.html

Welcome shadows110! You have an interesting project, but first please read the advice in the topic "How to get the best from this forum". There is a proper way to post code, this allows us to help you. Taking what you posted and putting into a readable form takes a lot of time many do not want to spend. It will only take you another 10 seconds after your figure it out. l have no clue as to what each button is or how it interacts with your code, post an annotated schematic showing how you have wired it, not pictures such as frizzy drawings they are useless. Include links to "Technical information" on the hardware parts, links to sales outlets like azon are next to useless. Doing this will have a big positive effect on your answers and will improve the accuracy of the answer a lot.

1 Like

A basic wiring diagram

The Jukebox

The 1st Sketch is from [GitHub - stevenb9/WS2812B-Jukebox: Arduino program for WS2812B Jukebox Upgrade - stevenbreuls.com]
The 2nd Sketch is from [rgb-pixel/RGB_REACTIVE.ino at main · mahesh9123/rgb-pixel · GitHub]
I am nowhere near skilled enough to write this.

We could do with the full wiring diagram. You have not wired up the switch correctly. You wire a switch between input and ground, and then you enable the internal pull up resistor. Then a read gives a High When not pressed and a Low when pressed.

You have no resistor in series with the strip's data line 220r to 512R. And you have no large capacitor across the power rails of the strip at the start of the strip.
No indication where the power comes from, or any way that the grounds are wired up.

You just have a block that says analogue sound sensor, no part number, no link to it so no idea how it works.

What did you have difficulty understanding in that link I posted. If you don't tell me then I don't know.

1 Like

I will help others that have an idea of what a schematic is. Maybe the OP may even get the code posted so we do not have to download it.

#include <FastLED.h>

#define LED_PIN     7
#define BTN_PIN     4
#define NUM_LEDS    144
#define BRIGHTNESS  255
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define UPDATES_PER_SECOND 200

CRGB leds[NUM_LEDS];
 
int counter = 0;
int buttonState = 0;

CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;

void setup() {
    delay( 1500 ); // power-up safety delay
    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    FastLED.setBrightness(  BRIGHTNESS );
    pinMode(BTN_PIN, INPUT_PULLUP);
    Serial.begin(9600);

    currentPalette = RainbowColors_p;
    currentBlending = LINEARBLEND;
}

void loop()
{
    ChangePalettePeriodically();
    
    static uint8_t startIndex = 0;
    startIndex = startIndex + 1; /* motion speed */
    
    FillLEDsFromPaletteColors( startIndex);
    
    FastLED.show();
    FastLED.delay(1000 / UPDATES_PER_SECOND);
}

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
    uint8_t brightness = 255;
    
    for( int i = 0; i < NUM_LEDS; i++) {
        leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;
    }
}

void ChangePalettePeriodically()
{
  Serial.println(digitalRead(BTN_PIN));

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if(digitalRead(BTN_PIN) == LOW) {
    counter = counter + 1;
    delay(130);
  }

  if(counter == 4) {
    counter = 0;
  }

  if( counter ==  0)  { currentPalette = RainbowColors_p;        currentBlending = LINEARBLEND; }
  if( counter == 1)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }
  if( counter == 2)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }
  if( counter == 3)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }
  if( counter == 4)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
}

// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
    for( int i = 0; i < 16; i++) {
        currentPalette[i] = CHSV( random8(), 255, random8());
    }
}

void SetupBlackAndWhiteStripedPalette()
{
    // 'black out' all 16 palette entries...
    fill_solid( currentPalette, 16, CRGB::Black);
    // and set every fourth one to white.
    currentPalette[0] = CRGB::White;
    currentPalette[4] = CRGB::White;
    currentPalette[8] = CRGB::White;
    currentPalette[12] = CRGB::White;
    
}

// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
    CRGB purple = CHSV( HUE_PURPLE, 255, 255);
    CRGB green  = CHSV( HUE_GREEN, 255, 255);
    CRGB black  = CRGB::Black;
    
    currentPalette = CRGBPalette16(
                                   green,  green,  black,  black,
                                   purple, purple, black,  black,
                                   green,  green,  black,  black,
                                   purple, purple, black,  black );
}

const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
    CRGB::Red,
    CRGB::Gray, // 'white' is too bright compared to red and blue
    CRGB::Blue,
    CRGB::Black,
    
    CRGB::Red,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Black,
    
    CRGB::Red,
    CRGB::Red,
    CRGB::Gray,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Blue,
    CRGB::Black,
    CRGB::Black
};
//Develop by creative KHOPDI
https://youtu.be/6g7AUs74dV8

//NOTE:-ADJUST/SET BY POTENTIOMETER OF SOUND SENSOR IF LESS NUMBER OF PATTERN OBSERVE

#include <FastLED.h>

int r=152;
int g=0;
int b=10;

#define LED_PIN     5            //CONNECT DATA PIN OF PIXEL WITH 5 NUMBER PIN OF ARDUINO
#define NUM_LEDS    60           //CHANGE THE VALUE IF YOU WANT TO USE DIFFRENT NUMBER OF LED IN YOUR STRIP,HERE IN MY STRIP NUMBER OF LED IS 60 SO I SET IT 60.

CRGB leds[NUM_LEDS];
CRGB led[NUM_LEDS];
int s=0;

void setup() {

  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  for (int i = NUM_LEDS/2; i >= 0; i--) 
  {
     leds[i] = CRGB ( r,g,b);
     leds[NUM_LEDS-i] = CRGB (r,g,b );
     delay(40);
    FastLED.show();
  }
  Serial.begin(9600);
   pinMode(A0,INPUT);

}
void loop()
{
  s=analogRead(A0);
  s=s*2;
 // Serial.println(s);
 // delay(50);
  if((s>=450)&&(s<=550))
  {
    leds[(NUM_LEDS/2)-1]=CRGB (0, 0, 255);
    leds[NUM_LEDS/2]=CRGB (0, 0, 255);
  }
  else if((s>=400)&&(s<=450))
  {
    leds[(NUM_LEDS/2)-1]=CRGB (153, 153, 0);
    leds[NUM_LEDS/2]=CRGB (153, 153, 0);
  }
  else if((s>=350)&&(s<=400))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (255, 50, 255);
    leds[NUM_LEDS/2]=CRGB (255, 50, 255);
   }
   else if((s>=300)&&(s<=350))
  {
    leds[(NUM_LEDS/2)-1]=CRGB (10, 25, 217);
    leds[NUM_LEDS/2]=CRGB (10, 25, 217);
  }

    else if((s>=276)&&(s<=300))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (50, 50, 150);
    leds[NUM_LEDS/2]=CRGB (50, 50, 150);
   }
   else if((s>=250)&&(s<=275))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (230, 0, 10);
    leds[NUM_LEDS/2]=CRGB (230, 0, 10);
   }
  else if((s>=235)&&(s<=250))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (0, 160, 0);
    leds[NUM_LEDS/2]=CRGB (0, 160, 0);
   }
   else if((s>=200)&&(s<=230))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (1, 0, 1);
    leds[NUM_LEDS/2]=CRGB (1, 0, 1);
   }
  else
  {
     leds[(NUM_LEDS/2)-1] = CRGB ( r,s-100,b);
     leds[NUM_LEDS/2] = CRGB ( r,s-100,b);
  }
    for (int i = 0; i <= ((NUM_LEDS/2)-2); i++) 
  {
     leds[i] = leds[i+1];
     leds[NUM_LEDS-1-i] = leds[(NUM_LEDS)-i-2];
     
  }
 FastLED.show();
 delay(25);

}

The Pull Up wiring diagram is as the online diagrams I looked at and the button works with the 1st sketch fine.
I am missing the 330ohm resister from the pin 7 data line and that is ordered although the lights work ok as is.
The Analog Sound Sensor is a DSRobot unit part number DFR0034 which will be connected to the Arduino A0 pin as they advise.

Maybe you mean the switch isn't wired the way you want it to be.

The schematic I see has a 10K pullup resistor and a switch that woukd ground that if pressed. I wire switches this way alla time.

In the code we see

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if(digitalRead(BTN_PIN) == LOW) {
    counter = counter + 1;
    delay(130);
  }

Which you can complain about - the comment is wrong.

a7

No I mean correctly. The way of using a pull down resistor is incorrect, because it is more prone to interference.

Remember just because something functions does not mean it is right. A mistake often made by beginners.

But it is a pull up resistor, or I am blind, or you are on a different internet.

a7

#include <FastLED.h>

#define LED_PIN     7
#define BTN_PIN     5
#define NUM_LEDS    122
#define BRIGHTNESS  200
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB
#define UPDATES_PER_SECOND 200

CRGB leds[NUM_LEDS];
CRGB led[NUM_LEDS];

int counter = 0;
int buttonState = 0;
int r=152;
int g=0;
int b=10;
int s=0;

CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
extern CRGBPalette16 myAnalogSoundPalette;
extern const TProgmemPalette16 myAnalogSoundPalette_p PROGMEM;


void setup() {
    delay( 1500 ); // power-up safety delay
    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    FastLED.setBrightness(  BRIGHTNESS );
    pinMode(BTN_PIN, INPUT_PULLUP);
    Serial.begin(9600);

    currentPalette = RainbowColors_p;
    currentBlending = LINEARBLEND;
}

void loop()
{
    ChangePalettePeriodically();
    
    static uint8_t startIndex = 0;
    startIndex = startIndex + 1; /* motion speed */
    
    FillLEDsFromPaletteColors( startIndex);
    
    FastLED.show();
    FastLED.delay(1000 / UPDATES_PER_SECOND);
}

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
    uint8_t brightness = 255;
    
    for( int i = 0; i < NUM_LEDS; i++) {
        leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;
    }
}

void ChangePalettePeriodically()
{
  Serial.println(digitalRead(BTN_PIN));

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if(digitalRead(BTN_PIN) == LOW) {
    counter = counter + 1;
    delay(130);
  }

  if(counter == 4) {
    counter = 0;
  }

  if( counter ==  0)  { currentPalette = RainbowColors_p;        currentBlending = LINEARBLEND; }
  if( counter == 1)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }
  if( counter == 2)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }
  if( counter == 3)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }
  if( counter == 4)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
  if( counter == 5)  { currentPalette = myAnalogSoundPalette_p; currentBlending = LINEARBLEND; }
}

// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
    for( int i = 0; i < 16; i++) {
        currentPalette[i] = CHSV( random8(), 255, random8());
    }
}

void SetupBlackAndWhiteStripedPalette()
{
    // 'black out' all 16 palette entries...
    fill_solid( currentPalette, 16, CRGB::Black);
    // and set every fourth one to white.
    currentPalette[0] = CRGB::White;
    currentPalette[4] = CRGB::White;
    currentPalette[8] = CRGB::White;
    currentPalette[12] = CRGB::White;
    
}

// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
    CRGB purple = CHSV( HUE_PURPLE, 255, 255);
    CRGB green  = CHSV( HUE_GREEN, 255, 255);
    CRGB black  = CRGB::Black;
    
    currentPalette = CRGBPalette16(
                                   green,  green,  black,  black,
                                   purple, purple, black,  black,
                                   green,  green,  black,  black,
                                   purple, purple, black,  black );
}

const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
    CRGB::Red,
    CRGB::Gray, // 'white' is too bright compared to red and blue
    CRGB::Blue,
    CRGB::Black,
    
    CRGB::Red,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Black,
    
    CRGB::Red,
    CRGB::Red,
    CRGB::Gray,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Blue,
    CRGB::Black,
    CRGB::Black
}

const TProgmemPalette16 myAnalogSoundPalette_p PROGMEM =

 {
   for (int i = NUM_LEDS/2; i >= 0; i--) 
  {
     leds[i] = CRGB ( r,g,b);
     leds[NUM_LEDS-i] = CRGB (r,g,b );
     delay(40);
    FastLED.show();
  }
    pinMode(A0,INPUT);

}
void setupmyAnalogSoundPalette()
{
  s=analogRead(A0);
  s=s*2;
 // Serial.println(s);
 // delay(50);
  if((s>=450)&&(s<=550))
  {
    leds[(NUM_LEDS/2)-1]=CRGB (0, 0, 255);
    leds[NUM_LEDS/2]=CRGB (0, 0, 255);
  }
  else if((s>=400)&&(s<=450))
  {
    leds[(NUM_LEDS/2)-1]=CRGB (153, 153, 0);
    leds[NUM_LEDS/2]=CRGB (153, 153, 0);
  }
  else if((s>=350)&&(s<=400))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (255, 50, 255);
    leds[NUM_LEDS/2]=CRGB (255, 50, 255);
   }
   else if((s>=300)&&(s<=350))
  {
    leds[(NUM_LEDS/2)-1]=CRGB (10, 25, 217);
    leds[NUM_LEDS/2]=CRGB (10, 25, 217);
  }

    else if((s>=276)&&(s<=300))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (50, 50, 150);
    leds[NUM_LEDS/2]=CRGB (50, 50, 150);
   }
   else if((s>=250)&&(s<=275))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (230, 0, 10);
    leds[NUM_LEDS/2]=CRGB (230, 0, 10);
   }
  else if((s>=235)&&(s<=250))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (0, 160, 0);
    leds[NUM_LEDS/2]=CRGB (0, 160, 0);
   }
   else if((s>=200)&&(s<=230))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (1, 0, 1);
    leds[NUM_LEDS/2]=CRGB (1, 0, 1);
   }
  else
  {
     leds[(NUM_LEDS/2)-1] = CRGB ( r,s-100,b);
     leds[NUM_LEDS/2] = CRGB ( r,s-100,b);
  }
    for (int i = 0; i <= ((NUM_LEDS/2)-2); i++) 
  {
     leds[i] = leds[i+1];
     leds[NUM_LEDS-1-i] = leds[(NUM_LEDS)-i-2];
     
  }
 FastLED.show();
 delay(25);

}

I have had a go at merging the 2 sketches and have no idea if they will work but the compiler keeps throwing up this error no matter what I do or where I place , or ;
Line 142.1 is ```
const TProgmemPalette16 myAnalogSoundPalette_p PROGMEM =


Compiler error message
test.ino:142:1: error: expected ',' or ';' before 'const'
 const TProgmemPalette16 myAnalogSoundPalette_p PROGMEM =
 ^~~~~

exit status 1

Compilation error: expected ',' or ';' before 'const'

Odd because when I tried this ( placing a ; after the previous } ) then that error disappeared.

However it was replaced by the error:-

error: expected primary-expression before 'for'
for (int i = NUM_LEDS/2; i >= 0; i--)

The thing is that there is no code to actually define this block of memory , just stuff about setting values in the FastLed's buffer.

You are missing a chunk of code, and what code you do have is not part of a block of memory definition.

Thanks for the info, I have removed all the errors except the expected , or ; before Const at line 142:1 which is same as before. Putting one in just throws other different errors but not the same as you had now.

#include <FastLED.h>

#define LED_PIN     7
#define BTN_PIN     5
#define NUM_LEDS    122
#define BRIGHTNESS  200
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB
#define UPDATES_PER_SECOND 200

CRGB leds[NUM_LEDS];
CRGB led[NUM_LEDS];

int counter = 0;
int buttonState = 0;
int r=152;
int g=0;
int b=10;
int s=0;

CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
extern CRGBPalette16 myAnalogSoundPalette;
extern const TProgmemPalette16 myAnalogSoundPalette_p PROGMEM;


void setup() {
    delay( 1500 ); // power-up safety delay
    FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
    FastLED.setBrightness(  BRIGHTNESS );
    pinMode(BTN_PIN, INPUT_PULLUP);
    Serial.begin(9600);

    currentPalette = RainbowColors_p;
    currentBlending = LINEARBLEND;
}

void loop()
{
    ChangePalettePeriodically();
    
    static uint8_t startIndex = 0;
    startIndex = startIndex + 1; /* motion speed */
    
    FillLEDsFromPaletteColors( startIndex);
    
    FastLED.show();
    FastLED.delay(1000 / UPDATES_PER_SECOND);
}

void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
    uint8_t brightness = 255;
    
    for( int i = 0; i < NUM_LEDS; i++) {
        leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;
    }
}

void ChangePalettePeriodically()
{
  Serial.println(digitalRead(BTN_PIN));

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if(digitalRead(BTN_PIN) == LOW) {
    counter = counter + 1;
    delay(130);
  }

  if(counter == 4) {
    counter = 0;
  }

  if( counter ==  0)  { currentPalette = RainbowColors_p;        currentBlending = LINEARBLEND; }
  if( counter == 1)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }
  if( counter == 2)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }
  if( counter == 3)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }
  if( counter == 4)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
  if( counter == 5)  { currentPalette = myAnalogSoundPalette_p; currentBlending = LINEARBLEND; }
}

// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
    for( int i = 0; i < 16; i++) {
        currentPalette[i] = CHSV( random8(), 255, random8());
    }
}

void SetupBlackAndWhiteStripedPalette()
{
    // 'black out' all 16 palette entries...
    fill_solid( currentPalette, 16, CRGB::Black);
    // and set every fourth one to white.
    currentPalette[0] = CRGB::White;
    currentPalette[4] = CRGB::White;
    currentPalette[8] = CRGB::White;
    currentPalette[12] = CRGB::White;
    
}

// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
    CRGB purple = CHSV( HUE_PURPLE, 255, 255);
    CRGB green  = CHSV( HUE_GREEN, 255, 255);
    CRGB black  = CRGB::Black;
    
    currentPalette = CRGBPalette16(
                                   green,  green,  black,  black,
                                   purple, purple, black,  black,
                                   green,  green,  black,  black,
                                   purple, purple, black,  black );
}

const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
    CRGB::Red,
    CRGB::Gray, // 'white' is too bright compared to red and blue
    CRGB::Blue,
    CRGB::Black,
    
    CRGB::Red,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Black,
    
    CRGB::Red,
    CRGB::Red,
    CRGB::Gray,
    CRGB::Gray,
    CRGB::Blue,
    CRGB::Blue,
    CRGB::Black,
    CRGB::Black
}

const TProgmemPalette16 myAnalogSoundPalette_p PROGMEM =
{

void setup()
 {
   for (int i = NUM_LEDS/2; i >= 0; i--) 
  
     leds[i] = CRGB ( r,g,b);
     leds[NUM_LEDS-i] = CRGB (r,g,b );
     delay(40);
    FastLED.show();
  }

   pinMode(A0,INPUT);
    

void loop()
{
  s=analogRead(A0);
  s=s*2;
 // Serial.println(s);
 // delay(50);
  if((s>=450)&&(s<=550))
  {
    leds[(NUM_LEDS/2)-1]=CRGB (0, 0, 255);
    leds[NUM_LEDS/2]=CRGB (0, 0, 255);
  }
  else if((s>=400)&&(s<=450))
  {
    leds[(NUM_LEDS/2)-1]=CRGB (153, 153, 0);
    leds[NUM_LEDS/2]=CRGB (153, 153, 0);
  }
  else if((s>=350)&&(s<=400))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (255, 50, 255);
    leds[NUM_LEDS/2]=CRGB (255, 50, 255);
   }
   else if((s>=300)&&(s<=350))
  {
    leds[(NUM_LEDS/2)-1]=CRGB (10, 25, 217);
    leds[NUM_LEDS/2]=CRGB (10, 25, 217);
  }

    else if((s>=276)&&(s<=300))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (50, 50, 150);
    leds[NUM_LEDS/2]=CRGB (50, 50, 150);
   }
   else if((s>=250)&&(s<=275))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (230, 0, 10);
    leds[NUM_LEDS/2]=CRGB (230, 0, 10);
   }
  else if((s>=235)&&(s<=250))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (0, 160, 0);
    leds[NUM_LEDS/2]=CRGB (0, 160, 0);
   }
   else if((s>=200)&&(s<=230))
   {
     leds[(NUM_LEDS/2)-1]=CRGB (1, 0, 1);
    leds[NUM_LEDS/2]=CRGB (1, 0, 1);
   }
  else
  {
     leds[(NUM_LEDS/2)-1] = CRGB ( r,s-100,b);
     leds[NUM_LEDS/2] = CRGB ( r,s-100,b);
  }
    for (int i = 0; i <= ((NUM_LEDS/2)-2); i++) 
  {
     leds[i] = leds[i+1];
     leds[NUM_LEDS-1-i] = leds[(NUM_LEDS)-i-2];
     
  }
 FastLED.show();
 delay(25);

}

You still have the same problem, that definition has no code to initialise the palette and in this case now no closing brace }

Now you have made changes to your code that I would think is beyond you to implement, so where has this come from. It is no point in using extern if it is not referencing anything that is valid. It was fine the way you had the layout. It was just that the

Is not complete.