How to import another ino file

Im working on a project ( Project Dust ) that samples with one sensor and posts to the web. It works great. All the code is container in one .ino file.

I have another project ( Project CO2 )for a second sensor that also samples using a different sensor also on a Grove Shield.

Id like to incorporate the .ino file from my Project CO2, into my Project Dust such that both Dust and CO2 are reported to the web server.

What is the proper way to import that other .ino file in order to be able to just call the methods for Project CO2 and have them run in Project Dust?

Thanks

What is the proper way to import that other .ino file

You can't.

If you put both ino files into the same directory, both will be loaded when the IDE starts, and will be combined into one cpp file to be passed to the compiler. Of course, two setup()s and two loop()s will cause the linker fits.

Ok, so I guess I have to create a library file out of the sampling functions and web posting and just leave the calling of those in the .ino file.

Yes I understand they can't have 2 setups and 2 loops.

So how would I go about creating a separate file with functions for sampling and web posting so that I could include it in the main .ino file?

It would be a library, right?

Sounds like you are looking for this?

Demonstration code for several things at the same time
https://forum.arduino.cc/index.php?topic=223286.0

It would be a library, right?

A library is nothing more than a header file that defines what can be done and a source file that defines how to do it. Nothing scary about that.

Thanks Paul

No I don't mean it's scary. I've done it in objC programming. I'm just not sure how to do it for Arduino.

I'm just not sure how to do it for Arduino.

There are plenty of examples in the core libraries folder. There is even a tutorial.

Oh Cool! I just saw that.

Thanks PaulS

Hi Paul,

I read through the Libraries section in Arduino.cc but I only saw how to manage, install zip or manually install libraries.

From what I understand I would need to move my library code to a h/cpp file set.

My doubt is then, the language is still the same for the cpp file, right? Its still c++

the language is still the same for the cpp file, right? Its still c++

Yes.

There is a much easier way, on the top right corner, this is a down arrow under the search icon. Click that, select new tab, give it a name, and add some code. Very good/easy way to separate out your code.