In the first line, we create a new
13 and emits dits that are 200 milliseconds long. Then we emit the message
"Hello, world!" as Morse code. This way, we are able to send whatever message
we want, and we can change easily the pin and the length of a dit.
Now that we have defined the interface, we will implement it.
Fleshing Out the Morse Code Generator's Interface
Declaring interfaces is important, but it s as important to implement them.
Create a new tab and enter the filename
This is the right place to explain why we ve used
as the sketch name, even though it d be a more natural choice. The reason
is that the Arduino IDE turns every sketch (ending with
(ending with
.cpp
). For a sketch named
Telegraph.cpp
. In a case-insensitive file system, this conflicts with a file named
telegraph.cpp
, and it leads to some strange error messages.
Enter the following code now in the newly created tab:
TelegraphLibrary/telegraph.cpp
#include <ctype.h>
#include <Arduino.h>
#include "telegraph.h"
const
char* LETTERS[] = {
".-",
"-...", "-.-.", "-..",
"..-.", "--.",
"....", "..",
"-.-",
".-..", "--",
".--.", "--.-", ".-.",
"..-",
"...-", ".--",
"--.."
};
const
char* DIGITS[] = {
"-----", ".----", "..---", "...--",
"....-", ".....", "-....", "--...",
"---..",
"----."
};
Like most C++ programs, ours imports some libraries first. Because we need
functions such as
toupper
telegraph.h
to make our class declaration and its corresponding function decla-
rations available. But what is
Until now we haven t thought about where constants such as
OUTPUT
came from. They are defined in several header files that come with the
Chapter 4. Building a Morse Code Generator Library
Telegraph
object that communicates on pin
telegraph.cpp
Telegraph.ino
".",
// A-E
".---",
// F-J
"-.",
"---",
// K-O
"...",
"-",
// P-T
"-..-", "-.--",
// U-Y
// Z
// 0-3
// 4-7
// 8-9
later, we include
ctype.h
Arduino.h
good for?
www.it-ebooks.info
.
TelegraphLibrary
and not
Telegraph
.ino
) into a C++ file
it generates a C++ file named
, and we have to include
HIGH
,
64
LOW
, or
report erratum
discuss
Need help?
Do you have a question about the Arduino Uno and is the answer not in the manual?