{"id":72,"date":"2013-10-24T16:47:27","date_gmt":"2013-10-24T16:47:27","guid":{"rendered":"https:\/\/arduino-developer.com\/arduino\/?p=72"},"modified":"2014-09-26T18:01:00","modified_gmt":"2014-09-26T18:01:00","slug":"creating-a-library","status":"publish","type":"post","link":"https:\/\/arduino-developer.com\/arduino\/libraries\/creating-a-library","title":{"rendered":"Creating A Library"},"content":{"rendered":"<h4>\nLibrary Files<br \/>\n<\/h4>\n<p>\nA library contains a .h header file and a .c or .cpp&nbsp;source code file as a minimum. &nbsp;Additional files can be added as needed. &nbsp;The files should used inside a directory typically given the library name.\n<\/p>\n<h4>\nCreate a&nbsp;.h File<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n#ifndef MY_LIBRARY_H\t\t\/\/Do only once the first time this file is used\r\n#define\tMY_LIBRARY_H\r\n\r\n#include &quot;Arduino.h&quot;\r\n\r\nclass MyLibraryName\r\n{\r\n  public:\r\n    MyLibraryName(int pin);\r\n    void SampleFunction();\r\n  private:\r\n    int InternalVariable;\r\n};\r\n\r\n#endif\r\n<\/code><\/pre>\n<h4>\nCreate a&nbsp;.c&nbsp;File<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n#include &quot;Arduino.h&quot;\r\n#include &quot;MyLibraryName.h&quot;\r\n\r\n\/\/*********************************\r\n\/\/*********************************\r\n\/\/********** CONSTRUCTOR **********\r\n\/\/*********************************\r\n\/\/*********************************\r\nMyLibraryName::MyLibraryName(int pin)\r\n{\r\n  InternalVariable = pin;\r\n}\r\n\r\n\/\/*************************************\r\n\/\/*************************************\r\n\/\/********** SAMPLE FUNCTION **********\r\n\/\/*************************************\r\n\/\/*************************************\r\nvoid MyLibraryName::SampleFunction()\r\n{\r\n  InternalVariable = 2;\r\n}\r\n<\/code><\/pre>\n<h4>\nUsing It In A Project<br \/>\n<\/h4>\n<p>\nCopy the library files to a directory off the libraries sub directory of your sketchbook directory, e.g. YourSketchbook\\libraries\\MyLibraryName\\\n<\/p>\n<pre>\r\n<code>\r\n#include &lt;MyLibraryName.h&gt;\r\n\r\n\/\/Create an instance of the class\r\nMyLibraryname MyLibraryname1(3);\r\n\r\nMyLibraryname1.SampleFunction();\r\n<\/code><\/pre>\n<h4>\nNice Extras To Add<br \/>\n<\/h4>\n<p>\nSee Keywords and an Example of usage <a href=\"http:\/\/arduino.cc\/en\/Hacking\/LibraryTutorial\" target=\"_blank\">here<\/a>.\n<\/p>\n<p>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Library Files A library contains a .h header file and a .c or .cpp&nbsp;source code file as a minimum. &nbsp;Additional files can be added as needed. &nbsp;The files should used inside a directory typically given the library name. Create a&nbsp;.h File #ifndef MY_LIBRARY_H \/\/Do only once the first time this file is used #define MY_LIBRARY_H [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-72","post","type-post","status-publish","format-standard","hentry","category-libraries"],"_links":{"self":[{"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/posts\/72","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/comments?post=72"}],"version-history":[{"count":6,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/posts\/72\/revisions"}],"predecessor-version":[{"id":115,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/posts\/72\/revisions\/115"}],"wp:attachment":[{"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/media?parent=72"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/categories?post=72"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/arduino-developer.com\/arduino\/wp-json\/wp\/v2\/tags?post=72"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}