Hardware Reference
In-Depth Information
IDE that works on several platforms, including Windows, Linux, and Mac OS.
It is available from www.codeblocks.org/downloads/ .
The header i le is a i le that contains a description of the functions that you
will be writing. Its name is just as important as the name of the library and
folder it lives within. For example, when you import the EEPROM library, you
add this line:
#include <EEPROM.h>
This is the header i le. Typically, it has the same name as the folder it is held in,
but not always. For example, when importing the Wi-Fi library, you may see this:
#include <WiFi.h>
#include <WiFiServer.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
Several header i les are located inside this folder, and if you use the Import
Library functionality in the IDE, all header i les are automatically imported.
If named well, they clearly state what they do, so anyone using the library can
know what the headers do and if they are needed. Imagine another sort of name:
#include <stuff.h>
This isn't clear, and users will have no idea what this library does. Remember
to keep your library name precise and clear.
First, create a source i le named theAnswerToEverything.cpp . The source
i le is written in C++ and has the extension .cpp . Add the following contents
to the i le and save it:
int theAnswer()
{
return 42;
}
There is just this one function; it takes no parameters and returns an int . The
Arduino IDE still does not know about this function; it has to be declared . This
is the role of the header i le. Create a new i le named theAnswerToEverything.h
and add the following:
int theAnswer();
Did you see the difference? It is the same structure, only instead of having
source code within brackets, the line is immediately ended with a semicolon.
This is the declaration . It tells the compiler that this function exists, that it returns
an int , and that it takes no parameters. If called, the compiler will know that
it can i nd the source code within the .cpp i le.
Search WWH ::




Custom Search