0

Im working on a RGB LED matrix project (10 x 10 Neopixels) and I'm using classes to handle the different hardware components. Whats the best way to deal with multiple files in the project eg, I have a class which holds the various display functions such as writing text and drawing circles, but every time I change something it takes ages to compile (Greater than 30 seconds) is there a way to have multiple files without using classes?

Any help would be greatly appreciated.

Cheers

  • In my experience simply having multiple files should not inflate your compile time by that much. What Arduino are you using? i would try troubleshooting (i.e. what happens when there is 1 file with all your functionality? what happens when there are multiple files with less functionality?) – TanyaV Mar 27 '17 at 10:57
  • I'm using sublime with STINO as an instead of the IDE to program a nano v3 – Matt Mar 27 '17 at 10:58
  • You can have multiple files without implementing any classes. just make sure to include the arduino.h header in them if you want to use any arduino API (like "digitalWrite", pinMode, etc..) – TanyaV Mar 27 '17 at 11:03
  • Look at the compilation messages. Does it recompile everything when you change a single file? If so, you should probably file an issue. – Edgar Bonet Mar 27 '17 at 11:12
  • What version of the IDE and what host (Windows, Linux, etc)? If you are running on Windows you need to shut off the virus scan of generated files. – Mikael Patel Mar 27 '17 at 11:34
1

Yes you can have multiple files without classes.

Functions don't have to go in classes, see loop and setup for an example. All you have to do is declare the function in a header file and then implement it in a body.

so:

// File Bob.h
#ifndef __BOB_H__
#define __BOB_H__

int SomeFunction(const char val);

#endif // __BOB_H__ 

// File Bob.cpp
#include Bob.h
int SomeFunction(const char val)
{  
   return (int)val;
}


// File SketchName.ino
#include "Bob.h"

setup()
{
  ......... Stuff

Now in theory the compiler will only rebuild Bob.cpp when you change code in it. In practice you will change code in it and the compiler won't rebuild it and you'll tare your hair out until you remember that if all else fails, rebuild all!

In SketchName.ino some people will say you should always put your includes first, some will say last and some will say it makes no difference. In my experience its easier to fix duplicate definitions by changing your code so I always put 'my' includes last, because that way the compiler will report the errors against my code.

BTW 30 seconds is not a long build time. I've worked on projects taking 12+ hours, and missing a semi colon on those projects does not make you popular :)

  • Ahh, this sounds about right. I am using STINO with the full compile option switched on because I'm changing the cpp files quite often. I'll have a go at your suggestion when i get home tonight, cheers. – Matt Mar 27 '17 at 12:14
  • Sounds recognizable, build times of multiple hours. However, I hope you could check semicolons without having too do a full build. In my work full builds are scheduled at night, so waiting times can be some hours + 8+ hours depending when initiating a full build. – Michel Keijzers Mar 27 '17 at 14:18
  • Whats your methodology when working on huge programs, do you have some software for debugging or do you rely on the compiler throwing highlighting the errors? – Matt Mar 28 '17 at 8:06
  • It depends what the platform is. For Arduino I extract all the non-platform specific code out and get it compiling in Visual Studio (Community) and then write a set of tests to make sure every function and class does what I expect. I've also written some mock modules that offer some Arduino functionality (pinMode, digitalWrite, etc) so I can tests lower level code on the PC. Then switch to the Arduino as late as possible. The only way (AFAIK) to debug on an Arduino is Serial.Print or similar. – Code Gorilla Mar 28 '17 at 8:49
1

I noticed that it is very hard to use classes with the default IDE. Each file will be in a different tab, but normally each class has a header (.h) and implementation (.c) file, so 2 extra tabs per class.

If you have just 3-4 classes you can use the default IDE.

However, if you want to use more, you have to use e.g. Eclipse or Visual Studio, whatever IDE you like best.

Search for Eclipse/Arduino, I think there are multiple options.

Myself I use visualmicro ... it is free except you cannot use the debugger option.

I used several classes in my sketch and don't think the compile time was 30 seconds; it might be depending also on the amount of include files.

Also a complex program is not necessarily a program with many classes. I would say, that if you put too much functionality in one class (or one single sketch), you get a complex program.

  • 1
    I'm currently using STINO but ill have a look in to other IDE's. Cheers – Matt Mar 27 '17 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.