I have been through http://arduino.cc/en/Hacking/LibraryTutorial but I can't do it. Whenever I create a new sketch and try to save it as .cpp
or .h
from the Save As button in the Arduino IDE, it gets saved as _cpp
and _h
. I am not able to create a library this way. How do I create a new library? What am I missing here?
1 Answer
When you save a file using the Save As button from the Arduino IDE, it saves the current file as a sketch i.e. as an .ino
file.
To create a .cpp
and .h
files for working on a new library, you need to create the files alongside a sketch. For this, you can use the Tab button on the top right (circled in red).
Click on it, and select New Tab. You will get a bar at the bottom of the screen asking for a file name. Enter the name with extension (test.cpp
) and press Enter.
Your file has now been added to the current directory.
Similarly, follow the same steps for creating the .h
file.
Once your library is complete and ready to ship, you can move the .cpp
and .h
files to a separate directory and then add it under libraries.
-
do i copy the same code in .h and .cpp and what do i do after this because the tutorial i have been following is unclear Mar 2, 2014 at 5:05
-
@user121855 That deserves a separate question. That will involve a purely code-related answer, while this was more about the file structure.– asheeshrMar 2, 2014 at 5:32
-
my other question is here arduino.stackexchange.com/questions/550/… Mar 2, 2014 at 5:47
.cpp
and.h
files get renamed to_cpp
and_h
. Could you tell us how you are creating the files? Using the new file button on the right side of the Arduino IDE? Some other way?