Hi, relatively new to Arduino here and re-familiarizing myself with C++ after a long time.
I'm trying to figure out the simplest way to divide my project up into discrete parts, including use of classes and/or function pointers but with as little boilerplate as possible.
Given how the build process works, I think that might mean moving my loop() and setup() functions into a file late in the alphabet (e.g., z.ino). In that case, anything defined at file scope in another file will be available to it. If I then use the main sketch file as a place for globals and assume intermediate files won't have access to each other, should work?
Presumably the alternative (less hacky, but lots of extra code and files) is to just abandon .ino files and go with .h and .cpp and explicit #includes.
You can have one main .ino file and put setup() / loop() there. The rest of the modules would then be done with .h / .cpp files. I avoid the multiple .ino file hack. See my Reply #5 Here for some basic guidelines.
Arduino programs are generally pretty small. I find it easy enough to put it all in a single file, especially when I'm starting a project. I might use .h and .cpp if I have written a substantial class, but that's a rare occurence.
I view it like using multiple Arduinos for a project: don't do it until you have to.
If you foresee yourself building anything particularly complex, I'd suggest avoiding the Arduino IDE altogether and installing Visual Studio Code and the Platformio plugin. It's a far better development environment.
Never had an issue with .h / .cpp modules. The automatic prototype generator doesn't mess with those. And even in the (single) .ino file I provide my own prototypes for all functions so auto generator doesn't do anything.
Yes, I was not clear. I meant using one cpp file for everything or nearly, instead of one ino for everything.
Because the ino, even just one, can give problems. First time I got srsly burned it turned on having added a comment to my code… which is the purest of irony as I don't use comments much at all.
As you say, using cpp and function prototypes steps aside of any IDE build process. And just leaves you in the normal world of pain which is programming.