EasyManuals Logo

Arduino Pro Mini User Manual

Arduino Pro Mini
311 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #84 background imageLoading...
Page #84 background image
Arduino IDE, and you can find them in the
hardware/arduino/cores/arduino
directory
of the IDE. Have a look at
Arduino.h
(in older Arduino versions this file was
named
WProgram.h
). It contains all the constants we have used so far and many
more. It also declares many useful macros and the Arduinos most basic
functions.
When you edit regular sketches, you dont have to worry about including any
standard header files, because the IDE does it automatically behind the
scenes. As soon as you create more complex projects that contain real C++
code, you have to manage everything yourself. You have to explicitly import
all the libraries you need, even for basic stuff such as the Arduino constants.
After importing all necessary header files, we define two string arrays named
LETTERS
and
DIGITS
. They contain the Morse code for all letters and digits, and
well use them later to translate regular text into Morse code. Before we do
that, we define the constructor that is responsible for creating and initializing
new
Telegraph
objects:
TelegraphLibrary/telegraph.cpp
Telegraph::Telegraph(const int output_pin, const int dit_length) {
_output_pin = output_pin;
_dit_length = dit_length;
_dah_length = dit_length * 3;
pinMode(_output_pin, OUTPUT);
}
The constructor expects two arguments: the number of the pin the Morse
code should be sent to and the length of a dit measured in milliseconds. Then
it stores these values in corresponding instance variables, calculates the
correct length of a dah, and turns the communication pin into an output pin.
Youve probably noticed that all private instance variables start with an
underscore. I like that convention personally, but it isnt enforced by C++ or
the Arduino IDE.
Outputting Morse Code Symbols
After everything has been initialized, we can start to output Morse code
symbols. We use several small helper methods to make our code as readable
as possible:
TelegraphLibrary/telegraph.cpp
void Telegraph::output_code(const char* code) {
const unsigned int code_length = strlen(code);
for (unsigned int i = 0; i < code_length; i++) {
if (code[i] == '.')
report erratum discuss
Outputting Morse Code Symbols 65
www.it-ebooks.info

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Arduino Pro Mini and is the answer not in the manual?

Arduino Pro Mini Specifications

General IconGeneral
BrandArduino
ModelPro Mini
CategoryMotherboard
LanguageEnglish

Related product manuals