Can't make reference of class

You can find the code here: test_class/_main.ino at main · l3viz/test_class · GitHub

I made a Class "Module" with 3 instances(Sry if I'm naming it wrong, I'm new to the coding and my native language isn't english). moduleLeft, moduleRight, moduleMid.
at line 295 I try to make "q" some sort of placeholder for one of those 3 depending on what random number I get.
I get error no matching function for call to 'Module::Module()'

I could fix all this by simply rewrite the same code 3 times for each module, but that doesn4t seem to make any sense.

Can anyone explain how I can make q.SetColor(magenta); work in stead of moduleMid.SetColor(magenta);

thx in advance

Your Module class only has one constructor, so you need to construct it with the correct arguments that
match that constructor.

Since Module contains a reference to led, you must pass that in the constructor's arguments or you'll
break the rule that references are always valid (can't be NULL). Only pointers can be NULL in C++

kingofwoods:
Can anyone explain how I can make q.SetColor(magenta); work in stead of moduleMid.SetColor(magenta);

You could make 'q' a pointer:

  Module *q;
  q = moduleMid;
  q->SetColor(magenta);

Note the use of '->' in place of '.' when using a pointer.

Just so EVERYONE is on the same page..

His class code in code tags..

/*
 * MODULE CLASS DECLARATION
 */
#include <Adafruit_NeoPixel.h>

class Module {
  private:
    Adafruit_NeoPixel &led;
    boolean ledState;
    unsigned long timeLedNeedsToStayOn;
    uint32_t color;
    int hallBaseValue;

  public:
    Module(Adafruit_NeoPixel &led, uint32_t color, unsigned long timeLedNeedsToStayOn, boolean ledState, int hallBaseValue) {
      SetLed(led);
      SetColor(color);
      SetTimeLedOn(timeLedNeedsToStayOn);
      SetLedState(ledState);
      SetHallBaseValue(hallBaseValue);
    }


//------------  Setters ----------------
    void SetLed(Adafruit_NeoPixel &l) {
      led = l;
    }
    void SetColor(uint32_t c) {
      color = c;
    }
    void SetTimeLedOn(long t) {
      timeLedNeedsToStayOn = t;
    }
     void SetLedState(bool ls) {
      ledState = ls;
    }
    void SetHallBaseValue(int h) {
      hallBaseValue = h;
    }

//------------  Getters ----------------
    Adafruit_NeoPixel GetLed() {
      return led;
    }    
    uint32_t GetColor() {
      return color;
    }
    long GetTimeLedOn() {
      return timeLedNeedsToStayOn;
    }    
    bool GetLedState() {
      return ledState;
    }
    int GetHallBaseValue() {
      return hallBaseValue;
    }
    

//------------  Setters ----------------
    // Checks whether it is time to turn on or off the LED.
    void check() {
      led.setPixelColor(0, color);
      led.show();
    }

    void LedOff() {
      Serial.println("Led OFF");
      led.setPixelColor(0, 0, 0, 0);
      led.show();
    }
};

So.. Where is the code that fires up the neoPixel stuff? I see you have a pointer to it. But nothing calls its begin() method or anything.

-jim lee

johnwasser:
You could make 'q' a pointer:

  Module *q;

q = moduleMid;
 q->SetColor(magenta);



Note the use of '->' in place of '.' when using a pointer.

This worked for me. big thx

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