Monolithic code file

I am a programmer used to the Keil microcontroller IDE and as such am used to creating a structured file pattern for different peripherals and link them to Main.C. Like for instance one of the typical projects will have these files in the Project :frowning: refer attachment )

Main.c
LCD.c
I2C.c
LED Disp.c

All functions in other three files as referenced in the Main.c with an “extern” prefix.

just wanted to know if the Arduino IDE has this facility as none of the examples seem to have one such sample. They all seem to have monolithic code file.

I am just starting out on Arduino so please bear if this is a very basic query.

Thanks
Mogaraghu

You can have as many source files as you want - just stay away from the "main" name. ISTR, it causes issues. The standard extension is .ino and you can have as many .ino's as you want. All .ino files get munged into one large file before compiling. But if you use .cpp extensions that won't happen.

Most arduino projects are pretty small, so single files are generally sufficient.

All .ino files get munged into one large file before compiling.

Thanks for responding.

OK I can make many .ino files - but how are they going to be linked together ? I mean will each have a Setup() and Loop() ? In other words how do I make many .ino files into a single project and link the different variables ?

Mogaraghu:

All .ino files get munged into one large file before compiling.

Thanks for responding.

OK I can make many .ino files - but how are they going to be linked together ? I mean will each have a Setup() and Loop() ? In other words how do I make many .ino files into a single project and link the different variables ?

With .ino files you don’t have to do anything. Before it goes to compilation, the IDE stitches them all together so they get treated like one big file. The only issue is that they don’t always go in the order you want. I think it actually puts them together in alphabetical order, but don’t quote me on that.

I can't see why you would want to use "extern" very often.

Mogaraghu:

All .ino files get munged into one large file before compiling.

Thanks for responding.

OK I can make many .ino files - but how are they going to be linked together ? I mean will each have a Setup() and Loop() ? In other words how do I make many .ino files into a single project and link the different variables ?

As far as I’m aware you have only one setup() and one loop() in your initial file. All the other .ino files are functions that you call from your initial file or from each other. Any constants and global variables declared in the initial file are accessible to all the functions, as they are all compiled into one big file. Obviously, local variables will only be accessible to the functions in which they are defined. The order in which the files are combined, apart from the initial file, is immaterial, as functions can be added in any order. The compiler sorts all the links out for you.

Thanks Henry.

Your reply kind off put things in perspective. I do agree that there is an argument against many .ino files but to me its a good way to organize things - like all functions pertaining to RTC go into one .ino and all functions pertaining to LCD go into another .ino and so on. I somehow hate scrolling like mad up and down to locate a function in a single LAARGE code page. But maybe its me.

Sounds like you want to create some libraries to me...