Neopixel wont start through class

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#include <EEPROM.h>

int ledFeedbackAmount = 5;            // Amount of feedback LEDS

// Leds                               (LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800)
Adafruit_NeoPixel ledStripLeft        (1, 4, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ledStripMid         (1, 3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ledStripRight       (1, 5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ledStripFeedback    (ledFeedbackAmount, 7, NEO_GRB + NEO_KHZ800);

// Halls
int hallLeft  = A2;
int hallMid   = A0;
int hallRight = A1;

// Colors
uint32_t white     = ledStripFeedback.Color(255, 255, 255);
uint32_t yellow    = ledStripFeedback.Color(255, 255, 0);
uint32_t orange    = ledStripFeedback.Color(255, 60, 0);
uint32_t red       = ledStripFeedback.Color(255, 0, 0);
uint32_t pink      = ledStripFeedback.Color(255, 0, 60);
uint32_t lightblue = ledStripFeedback.Color(0, 125, 255);
uint32_t green     = ledStripFeedback.Color(0, 255, 0);
uint32_t blue      = ledStripFeedback.Color(0, 0, 255);
uint32_t magenta   = ledStripFeedback.Color(255, 0, 255);
uint32_t ledOff    = ledStripFeedback.Color(0, 0, 0);

//Module moduleName(Adafruit_NeoPixel led, uint32_t color, unsigned long timeLedNeedsToStayOn, boolean ledState, int hallBaseValue) {

//States
bool stateLeft = 0;

void setup()
{
  #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
    clock_prescale_set(clock_div_1);
  #endif
  Serial.begin(9600);
  pinMode(hallLeft,   INPUT);
  pinMode(hallMid,    INPUT); 
  pinMode(hallRight,  INPUT); 
  ledStripLeft.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)  
  ledStripMid.begin();            // INITIALIZE NeoPixel strip object (REQUIRED)  
  ledStripRight.begin();          // INITIALIZE NeoPixel strip object (REQUIRED)
  ledStripFeedback.begin();       // INITIALIZE NeoPixel strip object (REQUIRED)
}

void loop(){
    
    ledStripLeft.setPixelColor(0, green);
    ledStripLeft.show();

    delay(2000);
    
    Module moduleLeft(ledStripLeft, red, 2000, 1, analogRead(hallLeft));
    moduleLeft.check();
    delay(500);
    moduleLeft.LedOff();
    delay(300);
}
/*
 * 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 ----------------
    void GetLed() {
      return led;
    }    
    uint32_t GetColor() {
      return color;
    }
    void GetTimeLedOn() {
      return timeLedNeedsToStayOn;
    }    
    void GetLedState() {
      return ledState;
    }
    void GetHallBaseValue() {
      return hallBaseValue;
    }
    

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

    void LedOff() {
      led.setPixelColor(0, 0, 0, 0);
      led.show();
    }
};

So Im cracking my head over this problem for the last couple of days. My led turns green without a problem. It even prints the color inside my class.check() but it just simply wont change to the color red. what am i doing wrong?

Is there any possibility you are specifying the wrong LED types? 3 color instead of 4 color or vice versa? 'Cause it sounds like you may have that problem. Also, just setup a SIMPLE test on each just a set color show() kind of thing to prove that you can talk to them and they are doing what you are telling them to do.

-jim lee

I agree, you need to trim a lot of fat from it for testing, to make sure you're not making a non-LED related error.

Why are you creating a new instance of the Module class on every pass through loop()?

Also:

 Module(Adafruit_NeoPixel led, uint32_t color, unsigned long timeLedNeedsToStayOn, boolean ledState, int hallBaseValue) {

In the constructor, you're passing the Adafruit_NeoPixel object by value to the Module class constructor. This creates a copy of the Adafruit_NeoPixel object (using that class's Copy Constructor). This is almost surely not what you want to do. Pass a reference or pointer instead.

jimLee:
Is there any possibility you are specifying the wrong LED types? 3 color instead of 4 color or vice versa? 'Cause it sounds like you may have that problem. Also, just setup a SIMPLE test on each just a set color show() kind of thing to prove that you can talk to them and they are doing what you are telling them to do.

-jim lee

aarg:
I agree, you need to trim a lot of fat from it for testing, to make sure you're not making a non-LED related error.

I alrdy tested the led, it works fine. If I call it by its name it shines green. If I create a class, where led is the correct Adafruit he refuses to shine.

gfvalvo:
Why are you creating a new instance of the Module class on every pass through loop()?

**Its just testing. I just want to make the led work so no fancy stuff. **

Also:

 Module(Adafruit_NeoPixel led, uint32_t color, unsigned long timeLedNeedsToStayOn, boolean ledState, int hallBaseValue) {

In the constructor, you're passing the Adafruit_NeoPixel object by value to the Module class constructor. This creates a copy of the Adafruit_NeoPixel object (using that class's Copy Constructor). This is almost surely not what you want to do. Pass a reference or pointer instead.

How do I do that? I'm really just a novice and for my project I need a class?

kingofwoods:
How do I do that? I'm really just a novice and for my project I need a class?

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;
    }

PaulMurrayCbr:

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;
   }

Same result. My led doesnt seem to respond to any of the code. I know it goes into my Check() method becase it prints my Serial.print stuff

kingofwoods:
Same result.

Post your complete new code that gives "same result".

/*
 * 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();
    }
};
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#include <EEPROM.h>

int ledFeedbackAmount = 5;            // Amount of feedback LEDS

// Leds                               (LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800)
Adafruit_NeoPixel ledStripLeft        (1, 4, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ledStripMid         (1, 3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ledStripRight       (1, 5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel ledStripFeedback    (ledFeedbackAmount, 7, NEO_GRB + NEO_KHZ800);

// Halls
int hallLeft  = A2;
int hallMid   = A0;
int hallRight = A1;

// Colors
uint32_t white     = ledStripFeedback.Color(255, 255, 255);
uint32_t yellow    = ledStripFeedback.Color(255, 255, 0);
uint32_t orange    = ledStripFeedback.Color(255, 60, 0);
uint32_t red       = ledStripFeedback.Color(255, 0, 0);
uint32_t pink      = ledStripFeedback.Color(255, 0, 60);
uint32_t lightblue = ledStripFeedback.Color(0, 125, 255);
uint32_t green     = ledStripFeedback.Color(0, 255, 0);
uint32_t blue      = ledStripFeedback.Color(0, 0, 255);
uint32_t magenta   = ledStripFeedback.Color(255, 0, 255);
uint32_t ledOff    = ledStripFeedback.Color(0, 0, 0);

//Module moduleName(Adafruit_NeoPixel led, uint32_t color, unsigned long timeLedNeedsToStayOn, boolean ledState, int hallBaseValue) {
Module moduleLeft(ledStripLeft, red, 2000, 1, analogRead(hallLeft));

//States
bool stateLeft = 0;

void setup()
{
  #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
    clock_prescale_set(clock_div_1);
  #endif
  Serial.begin(9600);
  pinMode(hallLeft,   INPUT);
  pinMode(hallMid,    INPUT); 
  pinMode(hallRight,  INPUT); 
  ledStripLeft.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)  
  ledStripMid.begin();            // INITIALIZE NeoPixel strip object (REQUIRED)  
  ledStripRight.begin();          // INITIALIZE NeoPixel strip object (REQUIRED)
  ledStripFeedback.begin();       // INITIALIZE NeoPixel strip object (REQUIRED)
}

void loop(){
    Serial.println("LED PINK ON");
    ledStripLeft.setPixelColor(0, pink);
    ledStripLeft.show();

    delay(2000);
    
    moduleLeft.check();
    delay(5000);
    moduleLeft.LedOff();
    delay(3000);
}

So it prints “LED PINK ON”
It makes my led go PINK.
No changing colors, but it does print “Led off” so i know he reads the methods.

Is all your code in a single .ino file, or is it split between .ino, .h, and .cpp files?

EDIT:
Regardless, the code you posted doesn’t compile. So, it’s not surprising that it doesn’t work.

Its in 3 files. And here it compiles fine. I can change the color of my led in my _main.ino file rule
ledStripLeft.setPixelColor(0, pink);

So the led works, just not through the class for some reason.

test_classes
--test-classes.ino (empty)
--Modules.ino
--_main.ino

kingofwoods:
Its in 3 files.

Then post 3 files -- with names indicating which is which.

I placed them all here.

Put your Module class in a header file (rename Module.ino to Module.h) and include that header in the sketch. Arduino IDE has a (sometimes) weird way of amalgamizing sketches split into multiple ino's.

That code won't compile. You're not properly initializing the Adafruit_NeoPixel reference in the class's constructor. You must use an initializer list. See Case #2 here: When do we use Initializer List in C++? - GeeksforGeeks.

gfvalvo:
That code won’t compile. You’re not properly initializing the Adafruit_NeoPixel reference in the class’s constructor. You must use an initializer list. See Case #2 here: When do we use Initializer List in C++? - GeeksforGeeks.

Dude, I can not express how much I appreciated this. I have been stuck on this problem for over 2 weeks now. You solved it. I would never in a million years found this myself. First time ever I see something like this.
Thx a lot. Much appreciation

gfvalvo:
That code won't compile. You're not properly initializing the Adafruit_NeoPixel reference in the class's constructor. You must use an initializer list. See Case #2 here: When do we use Initializer List in C++? - GeeksforGeeks.

Drat - I missed that. I was coding blind - no compiler with me.