Hi ,
I am using an example sent to me by email which I opened by unzipping from my downloads folder. The .cpp and .h files are in the same window so if I try to create a new sketch and edit it, it won't compile. I cant find out how to install the .h file properly and if I could what would happen about the .cpp file?
I think you need to add the .cpp and .h files as a library.
You can do that straight from the ZIP file.
On the menu bar, click on 'Sketch', then 'Include Library', and then 'Add ZIP Library'.
Then navigate to the ZIP file.
Hi @ed1arris.
An Arduino sketch is a folder. Although many Arduino sketches contain only a single .ino
file, they may consist of multiple code files. Arduino IDE displays all the files of the sketch folder as editor tabs. So even though it is true to say the files are "in the same window", you should keep in mind that the more significant factor is that they are in the same folder.
If you like, you can simply copy the additional files to the folder of the new sketch. A convenient way to access the folder of an Arduino sketch is to open the sketch in Arduino IDE and then select Sketch > Show Sketch Folder... from the Arduino IDE menus. The sketch folder will then open in your file file manager application and you can copy the files to and from each of the folders from there.
Or if you don't want to maintain multiple copies of those files, you can install them as a library as @JohnLincoln suggested. Then any of your sketches can use the code from those files. You can do that by creating a folder under the libraries
subfolder of your Arduino sketchbook folder, then moving the files from the sketch folder to the library folder you created. If you don't know the location of the sketchbook folder, select File > Preferences from the Arduino IDE menus and then note the path that is shown in the "Sketchbook location" preference.
Thanks both, very clear explanations.
Glad to help.