Code error

Hi this is me again :smiley:

I have a code to light up 2 w2812b led strip but i have all time the same error. I want put on both strips the same signal ,but idk how to code it.

Error: ‚ÄėChangePalettePeriodically‚Äô was not declared in this scope

#include <FastLED.h>

#define LED_PIN1 5
#define LED_PIN2 6
#define NUM_LEDS1 79
#define NUM_LEDS2 41
#define LED_TYPE    WS2812
#define COLOR_ORDER GRB

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

CRGBPalette16 currentPalette;
TBlendType    currentBlending;

extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;

void setup() {
    delay( 3000 ); // power-up safety delay
    FastLED.addLeds<LED_TYPE, LED_PIN1, COLOR_ORDER>(strip1, NUM_LEDS1);
    FastLED.addLeds<LED_TYPE, LED_PIN2, COLOR_ORDER>(strip2, NUM_LEDS2);
  
    currentPalette = RainbowColors_p;
    currentBlending = LINEARBLEND;
}


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

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

       for( int i = 0; i < NUM_LEDS2; i++) {
        strip2[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;
    
    
    }
}





void ChangePalettePeriodically()
{
    uint8_t secondHand = (millis() / 1000) % 60;
    static uint8_t lastSecond = 99;
    
    if( lastSecond != secondHand) {
        lastSecond = secondHand;
        if( secondHand ==  0)  { currentPalette = RainbowColors_p;         currentBlending = LINEARBLEND; }
        if( secondHand == 10)  { currentPalette = RainbowStripeColors_p;   currentBlending = NOBLEND;  }
        if( secondHand == 15)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }
        if( secondHand == 20)  { SetupPurpleAndGreenPalette();             currentBlending = LINEARBLEND; }
        if( secondHand == 25)  { SetupTotallyRandomPalette();              currentBlending = LINEARBLEND; }
        if( secondHand == 30)  { SetupBlackAndWhiteStripedPalette();       currentBlending = NOBLEND; }
        if( secondHand == 35)  { SetupBlackAndWhiteStripedPalette();       currentBlending = LINEARBLEND; }
        if( secondHand == 40)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 45)  { currentPalette = PartyColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 50)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }
        if( secondHand == 55)  { 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, 
    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
};

Check you braces. Use the autoformat to line up the code and you should see your problem. That function is defined inside another function, which is illegal code.

The problem began when i added this

for( int i = 0; i < NUM_LEDS2; i++) {
        strip2[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
        colorIndex += 3;

(deleted)

The problem began when i added this

Did you try Auto Formatting the code as suggested ?

All functions should then start on the left hand margin. Does your ChangePalettePeriodically() function start there or have you got one or more curly brackets in the wrong place in the code ?

Im new in arduino i though that if one strip is working normal i will add the same code but change NUM_LEDS1 to NUM_LEDS2 and strip1 to strip2 all will work ,but i was in big mistake...

Well this guy is obviously just going to ignore our advise about the braces no matter how we state it. If he wants to waste time we should leave him to waste it on his own. No reason we should waste ours.

OP, the answer you need has been stated three times in this thread. Take some time to think about what has been said and you should be able to fix your code. You are missing one single character.

When i do auto formating i have only converted this

if( lastSecond != secondHand) {
        lastSecond = secondHand;
        if( secondHand ==  0)  { currentPalette = RainbowColors_p;         currentBlending = LINEARBLEND; }
        if( secondHand == 10)  { currentPalette = RainbowStripeColors_p;   currentBlending = NOBLEND;  }
        if( secondHand == 15)  { currentPalette = RainbowStripeColors_p;   currentBlending = LINEARBLEND; }
        if( secondHand == 20)  { SetupPurpleAndGreenPalette();             currentBlending = LINEARBLEND; }
        if( secondHand == 25)  { SetupTotallyRandomPalette();              currentBlending = LINEARBLEND; }
        if( secondHand == 30)  { SetupBlackAndWhiteStripedPalette();       currentBlending = NOBLEND; }
        if( secondHand == 35)  { SetupBlackAndWhiteStripedPalette();       currentBlending = LINEARBLEND; }
        if( secondHand == 40)  { currentPalette = CloudColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 45)  { currentPalette = PartyColors_p;           currentBlending = LINEARBLEND; }
        if( secondHand == 50)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND;  }
        if( secondHand == 55)  { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
    }

To this:

 if ( lastSecond != secondHand) {
      lastSecond = secondHand;
      if ( secondHand ==  0)  {
        currentPalette = RainbowColors_p;
        currentBlending = LINEARBLEND;
      }
      if ( secondHand == 10)  {
        currentPalette = RainbowStripeColors_p;
        currentBlending = NOBLEND;
      }
      if ( secondHand == 15)  {
        currentPalette = RainbowStripeColors_p;
        currentBlending = LINEARBLEND;
      }
      if ( secondHand == 20)  {
        SetupPurpleAndGreenPalette();
        currentBlending = LINEARBLEND;
      }
      if ( secondHand == 25)  {
        SetupTotallyRandomPalette();
        currentBlending = LINEARBLEND;
      }
      if ( secondHand == 30)  {
        SetupBlackAndWhiteStripedPalette();
        currentBlending = NOBLEND;
      }
      if ( secondHand == 35)  {
        SetupBlackAndWhiteStripedPalette();
        currentBlending = LINEARBLEND;
      }
      if ( secondHand == 40)  {
        currentPalette = CloudColors_p;
        currentBlending = LINEARBLEND;
      }
      if ( secondHand == 45)  {
        currentPalette = PartyColors_p;
        currentBlending = LINEARBLEND;
      }
      if ( secondHand == 50)  {
        currentPalette = myRedWhiteBluePalette_p;
        currentBlending = NOBLEND;
      }
      if ( secondHand == 55)  {
        currentPalette = myRedWhiteBluePalette_p;
        currentBlending = LINEARBLEND;

How about posting the complete program after Auto Formatting ?

(deleted)

Pokus46:
When i do auto formating i have only converted this

Look more closely.

If the code is formatted, then all the function definitions should be all the way to the left. Is that the case with the definition of ChangePalletPeriodically?

If you don't know what the braces { and } are for, then I would strongly suggest that you check out a basic C++ tutorial before you go much farther with Arduino.

spycatcher2k:
put a } on line 52

:slight_smile:

Yeah, sometimes you just gotta hit them upside the head with it. I would have really hoped that reply #3 would be enough.

I want to say THANKS YOU guys all is working ,and I'm sorry for make you annoyed :smiley: