Several files in a sketch

Hi all ! i'm working on a big sketch for an Arduino Mega 2560. As the sketch is quite large, I want to split it in several files. So, I made a new sketch called "Test" (very original !). Here is the code :

bool led = 0;

void setup()
    pinMode(13, OUTPUT);

void loop()

And I added a new tab called "functions.c" which contains that code :

void blink(bool *led)
    *led = !(*led);
    digitalWrite(13, led);

but that code doesn't compile.. How can I split my code in several files ? Thanks for your answers

There is a right arrow button on the same line as the sketch name. This allows separate 'tabbed' files to be created that will be concatenated to the main sketch by the arduino precompiler. I believe the tabbed files have to be named namewhatever.c or namewhaterver.cpp. These files will be saved separately in the same folder as the main sketch.


Thanks for your response. But that's exactly whay I've done ! To create my new tab, I clicked on the right arrox, next "New tab" and I typed "functions.c" as filename.

Another idea ?

From my tests, both should be sketches. Then add the pde file.

Enter the second code as sketch named "functions" rather than C code. It will create a functions.pde file in a "functions" folder. That is the file to add.

EDIT: I just ran another test. If you just rename your functions.c file to functions.pde, it should work also.

Thanks ! It works fine !

I think I would be interesting to put this tip in the documentation.

Have a nice day,