Arduino Library : How to Create Your Own Arduino Library

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] libraries are a collection of code that makes it easy for you to connect to a sensor display module for example the liquid crystal library makes it easy to talk to character LCD displays this video describes how to create arduino library from Arduino sketch a library typically consists of a header file H this contains the libraries definitions source code C++ this contains the libraries code a keyword file text this contains the keywords used in the library a readin file text this contains other information about the library examples you know these are to show user how to operate the library first look what's inside of our sketch a very simple sketch that you can use to blink or flash LEDs I'm using 8 LEDs in this sketch and there is the output of sketch you now I will convert this sketch into a class sketch we start by declaring a flashier class in private access modifier I have set eight variables for my LEDs which only class can use next I add a constructor in public access modifier the constructor has the same name as the class and its job is to initialize all the variables you this flashier class also contain a member function which our pin setup function pin setup function includes all pin configuration you finally I take my loop function and turn it into another member function called sequence one function you for using class features in main sketch we create an instance of the flashier class by calling constructor now we can use class member function in main sketch now we create a header file and source code file from this class sketch to create the header file and source code we will need to use a word editor of some sort I'll be using Visual Studio code you can use any editor create and select a folder for library files you open up a new file and save it as flash odd H you now open again a new file and save it as flasher dot c++ you source file contains the functions of the class the actual way to use the functions are not in the class they are on the C++ file so we put all these functions of the class into the C++ file you header files contain definitions of function variables which is imported or used into program by using the preprocessor include statement header file have an extension dot H which contains function Declaration and macro definition so in library header file the class contains the only functions and variables declaration to be used in your library they are just listed here for reference you after declaring the variables and function we will add these lines to the header file you the defined statement defines this file as a hejdå file so that it can be included within the source file the include of Arduino dot H gives this library access to the standard arduino types and constants hi digital rights etc the if not defined statement checks to see if the flasher dot H file isn't already defined this is to stop double declarations of any identifier within the library it is paired with a rendus statement at the bottom of the header you the include of Arduino dot H in source code file gives this library access to the standard Arduino types and constants hi digital rights etc it's son accessory for sketches but required for libraries as they're not Arduino files this will include the header file so that the source file has access to the function definitions in the flash' library this is where the constructor source code appears the double colon operator indicates that it is part of the flasher class and should be used for all constructors and functions that are part of a class you by rearranging of our class code and source file we have create our library now let's use it you copy the library folder into the Arduino libraries folder after copying it restart arduino ide you you can create keywords file by following method the keywords file is the file that tells the IDE which words are important and should be highlighted two different types of keywords exist keyword one for classes keyword two for functions you I have some other sketches that blink or flash LEDs with different ways you I have include all functions of these sketches and header file and source file you so you can use the library according to your way you you can download all of these files from the link below to further information and understanding I hope you now know how to create arduino library from Arduino sketch if you enjoyed this video please let me know I would also appreciate your feedback on the content and suggestions for improvement
Info
Channel: Arduino Magix
Views: 32,187
Rating: 4.5138888 out of 5
Keywords: Arduino Library, C++ Library for Arduino, how to make arduino library, arduino, arduino Programming, arduino Language, arduino class, Arduino OPP, Object Oriented Programming
Id: z2BstX2ff_g
Channel Id: undefined
Length: 16min 10sec (970 seconds)
Published: Fri Aug 17 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.