(Arduino Study) the method to make library

Original source code is like that

---
//sos_without_lib.pde
void dot();
void dash();

int pin = 13;

void setup()
{
  pinMode(pin, OUTPUT);
}

void loop()
{
  dot(); dot(); dot();
  dash(); dash(); dash();
  dot(); dot(); dot();
  delay(3000);
}

void dot()
{
  digitalWrite(pin, HIGH);
  delay(250);
  digitalWrite(pin, LOW);
  delay(250);
}

void dash()
{
  digitalWrite(pin, HIGH);
  delay(1000);
  digitalWrite(pin, LOW);
  delay(250);
}

...


To make library, we have to do 4 steps process,

step 1, write .h , .cpp files,   it is same c++ class, and copy into libraries\morse folder.
step 2, make keywords.txt,  and copy into libraries\morse folder.
step 3, make SOS.pde and copy libraries\morse\Examples\SOS
step 4, programing using the library

.h, .cpp

...
.h ->
#ifdef Morse_H
#define Morse_H

#include "WProgram.h"

class Morse{
  public:
    Morse(int pin);
    void dot();
    void dash();
  private:
    int _pin;

#endif

.cpp ->
#include "WProgram.h"
#include "morse.h"

Morse::Morse(int pin)
{
  pinMode(pin, OUTPUT);
  _pin = pin)
}

void Morse::dot()
{
  digitalWrite(pin, HIGH);
  delay(250);
  digitalWrite(pin, LOW);
  delay(250);
}

void Morse::dash()
{
  digitalWrite(pin, HIGH);
  delay(1000);
  digitalWrite(pin, LOW);
  delay(250);
}
---



...
//SOS.pde
#include < Morse.h>

Morse morse(13);
void setup(){}

void loop(){
     morse.dot();morse.dot();morse.dot();
     morse.dash();morse.dash();morse.dash();
     morse.dot();morse.dot();morse.dot();
     delay(3000);
}

---


so the directory is like that

\arduino-0022\libraries\Morse\keyword.txt,  Morse.cpp, Morse.h
\arduino-0022\libraries\Morse\Examples\SOS\SOS.pde


Comments

Popular posts from this blog

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

OpenCV Stitching example (Stitcher class, Panorama)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Real-time N camera stitching Class.

Optical Flow sample source code using OpenCV

OpenCV Drawing Example, (line, circle, rectangle, ellipse, polyline, fillConvexPoly, putText, drawContours)

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

SICK LMS511 sensor data acquisition interface (source code, C++/MFC)

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Image warping (using opencv findHomography, warpPerspective)