How to Instantiate an Object from Another Class and Have Other Functions Modify it?

Okay, yes, this bit that I pointed out earlier. What does the colon do? In gfvalvo's code, they didn't have the constructor in there (the .cpp file) at all, only in the header file. I don't know what difference that makes.

You mean the declaration for the other object? Like in this case, the NeoPixel object? The rest of what you said makes sense. Thank you for explaining things to me.

This is called a constructor initialization list.

For any hardware related classes, a constructor must contains only a declaration, and no interactions with the hardware itself, which at this point has not yet been initialized

It's an initializer list. This is one place where it must be used, when the constructor for a class data member takes arguments. In this case it's the Adafruit_NeoPixel class. The empty {} at the end is the body of the constructor, just like any other function. In this case it's empty so the constructor contains no code other than the initializer list. See Case #3 here.

It's the preferred syntax for variable initialization in C++ and offers some advantages enabling the compiler to find errors in your code.

The constructor in the code I posted was so trivial that providing its implementation in the .h file (class declaration) made things a little more compact without adding too much clutter. You can do that with member functions also, but I tend to do it only when they're a couple lines long. Too much implementation code in the class's declaration can make it harder for you to understand its interface at a glance.

Ohhh, that makes a lot more sense. That's exactly what I was looking for with my initial post. I'll try this and see if it fixes my problem (especially with the white flashes between blinks). Thank you so much for the pointers!

Okay, I implemented some of your changes and it works! It fixed the white flashes issue and everything works as intended. Thank you so much for the help. Not sure if I would've been able to figure this out on my own.

Arduino IDE take the sketch.ino, add few lines on it top and sends it to C++ compiler.

You can see that, if you set all warning on and compile any sketch (maybe Blink.ino), then near the same start of the listing you may see lines like



Compiling sketch...
some/long/path/...arduino7/bin/avr-g++ many params /temp/path/sketch.ino.cpp -o /temp/path/sketch.ino.cpp.o
Compiling libraries...
Compiling core...

So we see sketch.ino.cpp compiled by g++ (which is C++ compiler).

And if you compare the sketch.ino and the new sketch.ino.cpp under the temp directory, you will se, that there is only few lins added on the top.

Arduino IDE does it to help hide it uses C++ user to be not afraid of programming.

Which brings some problem there too, see Gammon Forum : Electronics : Microprocessors : How to avoid the quirks of the IDE sketch file pre-preprocessing

Many examples have something like Serial.begin() in setup() - clearly C++, not plain C.

But nearly all plain C constructions compiles in C++ with similar meaning. (Not all and there are some small differencies, but new user usually does not trigger that.)

Examples are usually writen as simple as possible, so not much of C++ is visible at first look (eg. Serial.print ). Also new users try to copy this style and usually write something simplified, which may look like plain C, while it is actually C++.

Arduino is mostly targeted to beginners, who do not want to learn programming, who do not want to detaily understand, what they are doing, but they have some visible results just now (or even sooner), regardles how many problems this may bring later. (like not talking about C++, calling programs "sketches", using some arbitrary number for pins, instead of port/bit and so on and so on ...)

(Well it did grow up so much, that it offers something even to more advanced users now. But the roots are to offer something to non-technical people to make blinking LED easy task.)