Question on Code, Tabs and multiple files

What is the best way to organize a larger project with multiple tabs. (Just C).

I’d like to setup a main sketch (INO), configuration file include.h (or similar) and various files for functions that need to be able to Serial.Println.

I started with:

  • program.ino
  • config.h
  • functions.c

Even by adding #include <arduino.h> I can’t get a simple function to use Serial.println. It works if put in the main sketch; but not functions.c

Looking for a little advice here.

Rename functions.c to functions.cpp and it will work.

If you prefer to have the Arduino IDE generate function prototypes for you then you can create tabs with no extension on the name, these will automatically be saved as .ino files. All .ino files are concatenated before compiling so you don't have to do any includes, it just provides a convenient way of breaking the sketch up to make it easier to navigate the code.

pert:
Rename functions.c to functions.cpp and it will work.

and add:

#include <Arduino.h>

to the *.cpp file…

Leave them as .INO files. The “main” one is the one with the same name as the folder name.

Give them sensible names related to the functions they perform. For example, you might have a group of functions related to the LCD display and another group related to a sensor. If you need to update the display functions for a different display, then they’re all gathered together and you know that the other functions don’t have any LCD code in them.

MorganS: Leave them as .INO files. The "main" one is the one with the same name as the folder name.

Not a fan of that option. It causes all the files to be mashed together before compilation. Thus, you lose the file-level variable and function scoping that C provides. I prefer using separate .cpp files with (possibly) individual .h files to segregate the main functional sections.