I am writing a library for my program that uses FastLED in some of

I am writing a library for my program that uses FastLED in some of the private methods and I am unsure how to make sure that the FastLED library should be included. I am getting a compile error: error: ‘leds’ was not declared in this scope

Specifically I think I am not including struct CRGB leds[NUM_LEDS] in the right place now.

Does it go in the .cpp file, the main sketch or inside the class in the .h file?

If your declaration of CRGB leds[NUM_LEDS]; is in the main sketch, your other files can include the line extern CRGB *leds; to reference that same piece of memory.

Great, and that just goes outside of any class code?

Put it near the top of any .C or .CPP file that references it.

Technical details: In C++ parlance, this is called a “forward declaration”. With the addition of the extern qualifier, this instructs the compiler to ignore the fact that the actual declaration is not in the current file.

Do I do something similar for the #defines as well?

#define LED_PIN 2
#define NUM_LEDS 50
#define BRIGHTNESS 100

I’ve been testing and it seems I have to include the #define statements in the main sketch and in the cpp files to get it to work. Is that right?

I’m really struggling to work out how to use FastLED inside an object. Are there any good examples of how this can be done simply, even a blink example?

OK so at the moment I have this in the header:

#define NUM_LEDS 50
#define LED_PIN 2
#define BRIGHTNESS 25

and

struct CRGB leds[NUM_LEDS];

in the .cpp

I would like to move the #defines to the main sketch is possible so they are more global as I will be introducing more classes further down the line.

Can I use references or pointers to the #defines?

@Luminous_Elements I tried using extern CRGB *leds; in the cpp file for my object and it compiles with no errors but the sketch doesn’t work. Is that really all I need to do, or should I also be changing how the other parts of the code referend leds ?

@Luminous_Elements I got it to work by using extern struct CRGB leds[]; without the forward declaration, but I think this might cause further problems down the line when I use it multiple classes