Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: octoWS inside a class won't work

  1. #1
    Junior Member
    Join Date
    Jan 2020
    Posts
    2

    octoWS inside a class won't work

    Hey guys!
    I'm trying to generalize an API for some led projects using octoWS2811 library and I'm having some problems.
    I want to put the octoWS object inside a class so it will be easier to handle, but when I upload and run the code it does not seem to work.

    the class definition (BasicLed.h) :

    Code:
    #include <Arduino.h>
    #include "OctoWS2811.h"
    #include "FastLED.h"
    #include "Defines.h"
    
    
    static DMAMEM int displayMemory[LEDSPERSTRIP*6];
    static int drawingMemory[LEDSPERSTRIP*6];
    static const int config = WS2811_GRB | WS2811_800kHz;
    
    
    class BasicLed{
    private:
    CRGB fastled[NUMOFPIX];
    // octo veriables
    OctoWS2811 octo = OctoWS2811(LEDSPERSTRIP, displayMemory, drawingMemory, config);
    
    public: 
    BasicLed();
    void set_color (u16 index ,u32 color);
    void fast2octo();
    void show();
    static u32 rgb2word(u8 r, u8 g, u8 b);
    void clear();
    
    };
    first of all for the display & drawing memory, if I dont define them as static I get a duplicate veriable error. I would really like to understand why, I dont declare them anywhere else in the code nor accept them as function inputs.
    2nd when I use the BasicLed class and try to light some leds nothing seems to work.

    Main.cpp code:

    Code:
    #include "BasicLed.h"
    
    
    BasicLed led;
    
    void setup() {
        led.set_color(0,RMASK);
        led.show();
    }
    
    
    void loop() {
    
    }
    ocotows.begin() is used in the constructor of the BasicLed class.

    Thanks for the help guys!

  2. #2
    Junior Member
    Join Date
    Jan 2020
    Posts
    2
    Hi Stav,
    I think it would make sense if you added BasicLed.cpp as well.
    Do you get a compiler issue that the object are not declared? Or are you just not getting any output on the leds?

  3. #3
    Junior Member
    Join Date
    Jan 2020
    Posts
    2
    I have BasicLed.cpp ,the header file is just for declarations and had no compiler error.
    I just managed to solve the problem
    I moved octo.begin() from the constructor to a function so i will call it inside setup{} instead of calling it when i create the global object.

    Now I have a new problem with an inherited class of BasicLed that wont output anything on the leds...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •