Build Your Own Arduino Library
by Azmi Deliaslan in Circuits > Arduino
956 Views, 6 Favorites, 0 Comments
Build Your Own Arduino Library
Hey everyone . In some projects you may have to create your own library when you are not able to use the ready libraries. Or you can create your own library by its own standards. Today , I will show you how easily you can build your own library and use in your code...
Introduce
=>WHAT IS .H FİLE?
An H file is a header file referenced by a C, C++ or Objective-C source code document. It may contain variables, constants, and functions that are used by otherfiles within a programming project. H files allow commonly used functions to be written only once and referenced by other source files when needed.
=>WHY DO WE USE C OR C++ FOR CREATING OUR LIBRARY ?
Arduino software consists of a development environment (IDE) and libraries. The IDE is written in Java and is based on the environment of the language Processing. The libraries are written in C and C ++ and compiled with AVR-GCC and AVR Libc. .
EXAMPLE CODE
In this project we create the library of the HC-SR04 sensor.
#include "mylibrary.h"
HC HC,HC1;
void setup() { Serial.begin(9600); HC.trigPin(A0); HC.echoPin(A1); HC1.trigPin(A2); HC1.echoPin(A3); }
void loop() { double distance1 = HC.calculate(A1,A0); double distance2 = HC1.calculate(A3,A2);
Serial.print("distance1 = "); Serial.println(distance1); Serial.print("distance2 = "); Serial.println(distance2); delay(500); }
PARTS
Here is a list of parts that i used to make this project:
- Arduino UNO
- Breadboard
- HC-SR04 *2 (you can use only one)
- Jumper Wires (male to male and male to female)
SCHEMA
RESULT
THANKS FOR VIEWING