-1

Good morning. I have a problem that I hope you understand. I'm trying to create a library from scratch. I've read and watched most videos and documentation that are on the internet. I can not understand and I'm not able to make one.

I hope someone can help me create a library that only shows a message that says "Hello World" in the serial port and give me the code if they are so kind. Also, it would be good if they could explain it to me.

I insist I know of many programming languages and realize this has made me a problem. I just need the code of the 3 parts so I can analyze it and understand it. I wait for your help.

7
  • 2
    A library is just c and c++ source files that contain code. What part of that do you not understand?
    – Majenko
    Jun 8, 2017 at 20:24
  • Think of a library as a class and you are calling that class with its subclasses, methods, and attributes from your script.
    – user23244
    Jun 8, 2017 at 21:55
  • It complicates me to create the files with the code
    – Diego
    Jun 8, 2017 at 21:59
  • Also, giving out code won't help someone learn it. You should learn about what algorithms are and learn how to plan out certain codes. No one goes into programming with a cold turkey. When you create a library, you need to think about what needs to get done and how you're going to get it done. You need to plan out on a piece of paper or chalkboard, write flow diagrams of particular objectives and methodology and write some pseudo code before you actually starting writing a program. If you do this, I guarantee it will help. Syntax is the hardest part about programming but you can research that.
    – user23244
    Jun 8, 2017 at 22:00
  • I know C ++ but in Arduino there are very few clear references to help that can create a library
    – Diego
    Jun 8, 2017 at 22:03

1 Answer 1

0

A simple example...

Create a folder named My_Library, and place it in the Arduino/libraries folder

Create a sketch named My_Library.h and add the following:

#ifndef __My_Library_H__
#define __My_Library_H__
#include "Arduino.h"

//example 1
#define myhello1() ( { \
   Serial.println(F("Hello World"); \
Serial.println(F("Hello World again"); \
} )

//example2
void myhello2() {
 Serial.println(F("another Hello World");
Serial.println(F("another Hello World again");
}

#endif

Place the the sketch in the "My_Library" folder

In the beginning of your sketch, add

#include <My_Library.h>

Then, wherever you want, add the following:

//example 1
myhello1();

//example2
myhello2();

I have not tested the above, but it should work fine. Regardless, this gives you a reasonable starting point.

For your last question concerning word colour, research "Arduino Libraries" regarding the "keywords.txt" file.

Not the answer you're looking for? Browse other questions tagged or ask your own question.