Need guidance on how to make this class accept an object as an argument.

I have some awesome LED strips running shows, but my code is rigid and unflexible so I am trying to convert to a OOP style. I am using the FastLED library.
Here is a small piece of working code I wrote. I would like to make the MovingRainbow class accept the CRGB object as an argument, specifically MovingRainbow::start() …

#include "Arduino.h"
#include "FastLED.h"
#include "myDefines.h"

#define DATA_PIN_TOP 10
#define DATA_PIN_Bottom 16
#define NUM_LEDS 28
#define DELTA_INDEX 10
#define START_INDEX 0

CRGB topLeds[NUM_LEDS];
CRGB bottomLeds[NUM_LEDS];

//////////////////////////////Moving Rainbow Class////////////////////////////////////////
class MovingRainbow
{    
  int rainbowSpeed;
  bool updateFlag = 0;
  
  public:
  MovingRainbow(int RSpeed){
          rainbowSpeed = RSpeed; 
  }
  void start(){ 
      fill_rainbow(topLeds, NUM_LEDS, START_INDEX, DELTA_INDEX);
      FastLED.show();
      updateFlag = 1;
  }

  void off(){
      updateFlag = 0;
  }   
           
};
////////////////////////////// End of Moving Rainbow Class /////////////////////////////////

MovingRainbow mRainbow(400);

void setup() {
    delay(2000);
    FastLED.addLeds<WS2812B, DATA_PIN_TOP, GRB>(topLeds, NUM_LEDS);
    FastLED.addLeds<WS2812B, DATA_PIN_BOTTOM, GRB>(bottomLeds, NUM_LEDS);
    mRainbow.start();    	
}

void loop() { 
  

    
}

7equivalents:
Here is a small piece of working code I wrote. I would like to make the MovingRainbow class accept the CRGB object as an argument, specifically MovingRainbow::start() ...

Are you saying you want the start() member function to accept a parameter: namely a CRGB object?

I'd start by overloading start() function to take one of those objects:

void start(const CRGB colors){ 
      fill_rainbow(colors, NUM_LEDS, START_INDEX, DELTA_INDEX);
      FastLED.show();
      updateFlag = 1;
  }

and call the function:

mRainbow.start(topLeds);

see if that compiles...

Hey, thanks alot! I appreciate that. It did not complile, but it got me close enough to poke it with a stick and make it do it’s thing! I changed

void start(const CRGB colors){};
to
void start(CRGB*colors){};

and then it worked. I’m not sure exactly what getting rid of const did, or for that matter the asterik either, but I’ve seen enough code snippets today that it made me think to do it. This is what my overall code looks like now, and it works!.. Thank you!

#include "FastLED.h"


#define DATA_PIN_TOP 10
#define DATA_PIN_BOTTOM 16
#define NUM_LEDS 28
#define DELTA_INDEX 10
#define START_INDEX 0

CRGB topLeds[NUM_LEDS];
CRGB bottomLeds[NUM_LEDS];

//////////////////////////////Moving Rainbow Class////////////////////////////////////////
class MovingRainbow
{   
  int rainbowSpeed;
  bool updateFlag = 0;
 
  public:
  MovingRainbow(int RSpeed){
          rainbowSpeed = RSpeed;
  }
  void start(CRGB*colors){
      fill_rainbow(colors, NUM_LEDS, START_INDEX, DELTA_INDEX);
      FastLED.show();
      updateFlag = 1;
  }

  void off(){
      updateFlag = 0;
  }   
           
};
////////////////////////////// End of Moving Rainbow Class /////////////////////////////////

MovingRainbow mRainbow(400);

void setup() {
  
    delay(2000);
    FastLED.addLeds<WS2812B, DATA_PIN_TOP, GRB>(topLeds, NUM_LEDS);
    FastLED.addLeds<WS2812B, DATA_PIN_BOTTOM, GRB>(bottomLeds, NUM_LEDS);
    mRainbow.start(topLeds);
}

void loop() {
 

   
}

7equivalents:
... or for that matter the asterik either

Since topLeds and bottomLeds are arrays of CRGB objects, you needed to tell ‘start’ that you’re passing it a pointer. That’s what the ‘*’ does. This probably would have worked also:

void start(CRGB colors[]) {}

7equivalents:
Hey, thanks alot! I appreciate that. It did not complile, but it got me close enough to poke it with a stick and make it do it's thing! I changed

void start(const CRGB colors){};
to
void start(CRGB*colors){};

and then it worked.

It compiled, I can guarantee it won't work.

The declaration of the full_rainbow function isn't shown, but based on the values you're passing it it expects an array of CRGB objects. A pointer to a single CRGB value won't work.

Thank you as well gfvalvo. I used the syntax you posted and it compiled and worked as well. I think I will stick with this syntax because I now understand that I'm passing it an array, and pointers are still a vague concept for me at this time. I do have one nuance that I don't understand about tha array. I'n this code block

void start(CRGB colors[], unsigned char numberOfLEDs, unsigned char index, unsigned char deltaIndex){
      fill_rainbow(colors, numberOfLEDs, index, deltaIndex);
      FastLED.show();
      updateFlag = 1;
  }

Shouldn't array "colors" be followed by square brackets in the fill_rainbow function? It fails to compile with the brackets there, but does compile without them.

Jiggy-Ninja, it may well not be operating the way it should, however my eyes can't tell because the LED strip does indeed fill up with the expected colors when the fill_rainbow function is called(using the "*" pointer syntax).

7equivalents:
Shouldn't array "colors" be followed by square brackets in the fill_rainbow function? It fails to compile with the brackets there, but does compile without them.

it depends on the object... in this case CRGB is a struct, not an array:

struct CRGB {
 union {
 struct {
            union {
                uint8_t r;
                uint8_t red;
            };
            union {
                uint8_t g;
                uint8_t green;
            };
            union {
                uint8_t b;
                uint8_t blue;
            };
        };
 uint8_t raw[3];
 };

great you figured it out

7equivalents:
I think I will stick with this syntax because I now understand that I’m passing it an array, and pointers are still a vague concept for me at this time.

In C/C++ they are essentially interchangeable - with proper change of syntax of course.

7equivalents:
Shouldn’t array “colors” be followed by square brackets in the fill_rainbow function?

No. You didn’t post the declaration for ‘fill_rainbow()’, but from the context of your other code it appears that this function is expecting a pointer to an array of CRGB objects (or per @BulldogLowell, structures). The name of an array will resolve to the pointer to the first element in that array. So, either of the following should work:

fill_rainbow(colors, numberOfLEDs, index, deltaIndex);

or

fill_rainbow(&colors[0], numberOfLEDs, index, deltaIndex);