object-oriented Programm for LED Stripes Compiler Error: decomposition...

Hello All,
i want to build a IR controlled Light with 6 LED Stripes of the Type WS2812B.
I wrote a Testcode for 2 Stripes, which worked without any Problems.
At first I created an CRGB Objekt for each Stripe with the Number of LEDS.

CRGB leds1[NUM_LEDS1];
CRGB leds2[NUM_LEDS2];

Then I initialized the 2 Stripes in the setup function

FastLED.addLeds<WS2812B, DATA_PIN1, GRB>(leds1, NUM_LEDS1);
  FastLED.addLeds<WS2812B, DATA_PIN2, GRB>(leds2, NUM_LEDS2);

then I can use the LED Stripe like the following Code piece shows

for(int i = 0; i<NUM_LEDS1; i++){
    leds1[i].setRGB(Rot1*hell1,Gruen1*hell1,Blau1*hell1);
    FastLED.show();
  }

I declared Parameters for Each Led Stripe for Example Red1 and Red 2, etc.
When I want to decrease the Red in the LED Stripe I need two functions one for the first and the other for the second stripe.
That is the Problem, the code works well, but is 500 Codelines long. When I add the missing 4 stripes the code length will explode.

So I want to write the Code object-oriented. I thought I can create one object for each led Stripe. This Object stores all the necessary attributes together.
I want also write functions to change color, Brightness etc., which i just have to call on each Object.
I came to the following code:

#include <IRremote.h>
#include <FastLED.h>
#define DATA_PIN 3
#define NUM_LEDS 4

class Strip: public CRGB{
  private: 
   int Red; 
   int Green;
   int Blue;
   float Bright; 
   int Numleds;
   
   public: 
   void setRGB(float bright, int Red, int Green, int Blue);
   void selectRGB(float bright, int Red, int Green, int Blue);
   void BlinkRGB(int iter, float bright, int Red, int Green, int Blue, int dur);
   void setRed(int red);
   void setGreen(int green);
   void setBlue(int blue);
   void setBright(float bright);
   void setNumleds(int numleds);
   int getRed();
   int getGreen();
   int getBlue();
   float getBright();
   int getNumleds();
};

// Get/Set Methods
void Strip::setRed(int red){
  Red = red;
}
void Strip::setGreen(int green){
  Green = green;
}
void Strip::setBlue(int blue){
  Blue = blue;
}
void Strip::setBright(float bright){
  Bright = bright;
}
void Strip::setNumleds(int numleds){
  Numleds=numleds;
}
int Strip::getRed(){
  return(Red);
}
int Strip::getGreen(){
  return(Green);
}
int Strip::getBlue(){
  return(Blue);
}
float Strip::getBright(){
  return(Bright);
}
int Strip::getNumleds(){
  return(Numleds);
}


void Strip::setRGB(float bright, int Red, int Green, int Blue){
  for(int i = 0; i<Numleds;i++){
   Strip[i].setRGB(Red*bright, green*bright, Blue*bright);
  }
  FastLED.show();
}
 void Strip::selectRGB(float hell, int Rot, int Gruen, int Blau){
  for(int i = 0; i<Numleds;i++){
    Strip[i].setRGB(Rot*hell, Gruen*hell, Blau*hell);
  }
 }

 void Strip::BlinkRGB(int durch, float hell, int Rot, int Gruen, int Blau, int dur){
  for(int j=0;j<durch; j++{
    for(int i=0; i<Numleds;i++){
      Strip[i].setRGB(Rot*hell, Gruen*hell, Blau*hell);
    }
    FastLED.show();
    delay(dur);
    for(int i=0; i<Numleds;i++){
      Strip[i].setRGB(0*hell, 0*hell, 0*hell);//errorline
    }
    FastLED.show();
    delay(dur);
  }
 }

Strip LED1 [NUM_LEDS];

void setup() {
FastLED.addLeds<GS1903, DATA_PIN, GRB>(LED1, NUM_LEDS);

}

void loop() {

}

I used the Inheritance an created a Class Strip with all the necessary attributes and I created get and set methods to change them. The Class Strip inherits from the Class CRGB.
The Problem is the code doesn’t work and the Compiler put auch an error which is called" decomposition declaration cannot be declared with type ‘Strip’". The line with the comment “//errorline” is the line which is marked by the Compiler. I think the Problem is based on the following Command:

Strip[i].setRGB(...);

I thought a lot about that Problem but i can’t find out my mistakes and didn’t get a solution.
I hope I explained my point of view accurately enough, so that you know what I mean and want to do.
It would be nice if you can give me some Support.

Thank You in advance
Felix

The IDE provides a simple control to copy the error message.

Please use it.

felixh_97:
The Class Strip inherits from the Class CRGB.

It won't work. If you check, you'll see that the size of a CRGB object is exactly 3 bytes. That's because the only data stored in the object are the R, G, and B color values. Thus, an array of CRGB objects has these pixel colors all stored in consecutive memory. FastLED depends on that relationship when it blasts the data out to the LED strip. When you add other data members to the class, you mess it up as the size of each object is no longer 3 bytes. Thus, FastLED doesn't send the proper data to the pixels in the strip.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.