0% found this document useful (0 votes)
103 views14 pages

ARDUINO Library

The document discusses creating custom Arduino libraries. It explains that a library is written in C++ and includes header and source code files. The header file contains function declarations while the source file contains definitions. It also provides an example library structure and shows how to include a library and call its functions from a sketch.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views14 pages

ARDUINO Library

The document discusses creating custom Arduino libraries. It explains that a library is written in C++ and includes header and source code files. The header file contains function declarations while the source file contains definitions. It also provides an example library structure and shows how to include a library and call its functions from a sketch.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Arduino Library

Arduino Library

•Membuat custom library


•Menggunakan custom Library
Membuat Custom
library arduino
Persyaratan
-mengetahui dasar C++
-mengetahui dasar OOP (pemrograman berorietasi objek)
Membuat Custom
library arduino
•Library Arduino ditulis mengunakan bahasa pemrograman C++
Library folder Struktur Folder library

Folder headerFileLibrary.

headerFileLibrary.h Berisi deklarasi


fungsi

sourceCodeLibrary.cpp Berisi defini fungsi

Berisi keyword yg
keywords.txt digunakan , akan
berwarna (foreground)
beda
Folder examples Berisi contoh code
Library folder Struktur Folder library

Folder headerFileLibrary

headerFileLibrary.h Berisi deklarasi


fungsi

sourceCodeLibrary.cpp
Berisi defini fungsi
Folder src
Berisi keyword yg
digunakan , akan
keywords.txt
berwarna (foreground)
beda
Folder examples Berisi contoh code
Library folder Struktur Folder library
Library folder

Contoh library Morse

Morse.h

Morse.cpp
Morse.h Morse.cpp
#include “Arduino.h"
#ifndef Morse_h #include "Morse.h"
#define Morse_h
Morse::Morse(int pin)
#include “Arduino.h“ {
pinMode(pin, OUTPUT);
_pin = pin;
class Morse }
{
void Morse::dot()
public: {
Morse(int pin); digitalWrite(_pin, HIGH);
delay(250);
void dot(); digitalWrite(_pin, LOW);
void dash(); delay(250);
}

private: void Morse::dash()


{
int _pin; digitalWrite(_pin, HIGH);
}; delay(1000);
digitalWrite(_pin, LOW);
delay(250);
#endif }
Menggunakan Library
#include <headerfilelibarary.h> #include <Morse.h>

Morse morse(13);
// buat object class library void setup()
namaClass namaobjek {
}

void loop()
//Gunakan fungsi objeck yg sdh dibuat {
namaObject.fungsi morse.dot();
morse.dash();
delay(3000);
}
#ifndef Morse_h
#define Morse_h

// #include statment and code go here.

#endif

Kode tsb diatas untuk mencegah eror krn


penambahan file header lebih dari satu (doble).
#ifndef Morse_h
#define Morse_h
#include "Arduino.h"

public: untuk mencegah eror krn


void dot(); penambahan file header
void dash();
private:
Int _pin;

#endif
#include "Arduino.h"
Header file Arduino.h yg berisi fungsi2 dasar arduino antara lain :
pinMode();
digitalWrite();
digitalRead();
analogRead();
analogReference();
analogWrite();
millis();
micros(;
delay();
delayMicroseconds();

Header file Arduino.h Harus ditambahkan sendiri ke library


yg kita buat .
Contoh1 - Menggunakan Library LiquidCrystal.h

#include<LiquidCrystal.h> #include<LiquidCrystal.h>

// buat object class library LiquidCrystal lcd( 3,4,5,6,7,8)


namaClass namaobjek
void setup()
{
}
void loop()
{
//Gunakan fungsi objeck yg sdh
dibuat lcd.setCursor(0, 0);
namaObject.fungsi lcd.print("test");
}

You might also like